{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 9.1 Creating a GroupBy Object from Scratch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Item</th>\n",
       "      <th>Type</th>\n",
       "      <th>Price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Banana</td>\n",
       "      <td>Fruit</td>\n",
       "      <td>0.99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Cucumber</td>\n",
       "      <td>Vegetable</td>\n",
       "      <td>1.25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Orange</td>\n",
       "      <td>Fruit</td>\n",
       "      <td>0.25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Tomato</td>\n",
       "      <td>Vegetable</td>\n",
       "      <td>0.33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Watermelon</td>\n",
       "      <td>Fruit</td>\n",
       "      <td>3.00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         Item       Type  Price\n",
       "0      Banana      Fruit   0.99\n",
       "1    Cucumber  Vegetable   1.25\n",
       "2      Orange      Fruit   0.25\n",
       "3      Tomato  Vegetable   0.33\n",
       "4  Watermelon      Fruit   3.00"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "food_data = {\n",
    "    \"Item\": [\"Banana\", \"Cucumber\", \"Orange\", \"Tomato\", \"Watermelon\"],\n",
    "    \"Type\": [\"Fruit\", \"Vegetable\", \"Fruit\", \"Vegetable\", \"Fruit\"],\n",
    "    \"Price\": [0.99, 1.25, 0.25, 0.33, 3.00]\n",
    "}\n",
    "\n",
    "supermarket = pd.DataFrame(data = food_data)\n",
    "\n",
    "supermarket"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<pandas.core.groupby.generic.DataFrameGroupBy object at 0x7fe669b2c6d0>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "groups = supermarket.groupby(\"Type\")\n",
    "groups"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Item</th>\n",
       "      <th>Type</th>\n",
       "      <th>Price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Banana</td>\n",
       "      <td>Fruit</td>\n",
       "      <td>0.99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Orange</td>\n",
       "      <td>Fruit</td>\n",
       "      <td>0.25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Watermelon</td>\n",
       "      <td>Fruit</td>\n",
       "      <td>3.00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         Item   Type  Price\n",
       "0      Banana  Fruit   0.99\n",
       "2      Orange  Fruit   0.25\n",
       "4  Watermelon  Fruit   3.00"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "groups.get_group(\"Fruit\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Item</th>\n",
       "      <th>Type</th>\n",
       "      <th>Price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Cucumber</td>\n",
       "      <td>Vegetable</td>\n",
       "      <td>1.25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Tomato</td>\n",
       "      <td>Vegetable</td>\n",
       "      <td>0.33</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       Item       Type  Price\n",
       "1  Cucumber  Vegetable   1.25\n",
       "3    Tomato  Vegetable   0.33"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "groups.get_group(\"Vegetable\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Price</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Type</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Fruit</th>\n",
       "      <td>1.413333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Vegetable</th>\n",
       "      <td>0.790000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              Price\n",
       "Type               \n",
       "Fruit      1.413333\n",
       "Vegetable  0.790000"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "groups.mean()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 9.2 Creating a GroupBy Object from a Data Set"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Company</th>\n",
       "      <th>Revenues</th>\n",
       "      <th>Profits</th>\n",
       "      <th>Employees</th>\n",
       "      <th>Sector</th>\n",
       "      <th>Industry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Walmart</td>\n",
       "      <td>500343.0</td>\n",
       "      <td>9862.0</td>\n",
       "      <td>2300000</td>\n",
       "      <td>Retailing</td>\n",
       "      <td>General Merchandisers</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Exxon Mobil</td>\n",
       "      <td>244363.0</td>\n",
       "      <td>19710.0</td>\n",
       "      <td>71200</td>\n",
       "      <td>Energy</td>\n",
       "      <td>Petroleum Refining</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Berkshire Hathaway</td>\n",
       "      <td>242137.0</td>\n",
       "      <td>44940.0</td>\n",
       "      <td>377000</td>\n",
       "      <td>Financials</td>\n",
       "      <td>Insurance: Property and Casualty (Stock)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Apple</td>\n",
       "      <td>229234.0</td>\n",
       "      <td>48351.0</td>\n",
       "      <td>123000</td>\n",
       "      <td>Technology</td>\n",
       "      <td>Computers, Office Equipment</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>UnitedHealth Group</td>\n",
       "      <td>201159.0</td>\n",
       "      <td>10558.0</td>\n",
       "      <td>260000</td>\n",
       "      <td>Health Care</td>\n",
       "      <td>Health Care: Insurance and Managed Care</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>SiteOne Landscape Supply</td>\n",
       "      <td>1862.0</td>\n",
       "      <td>54.6</td>\n",
       "      <td>3664</td>\n",
       "      <td>Wholesalers</td>\n",
       "      <td>Wholesalers: Diversified</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>Charles River Laboratories Intl</td>\n",
       "      <td>1858.0</td>\n",
       "      <td>123.4</td>\n",
       "      <td>11800</td>\n",
       "      <td>Health Care</td>\n",
       "      <td>Health Care: Pharmacy and Other Services</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>CoreLogic</td>\n",
       "      <td>1851.0</td>\n",
       "      <td>152.2</td>\n",
       "      <td>5900</td>\n",
       "      <td>Business Services</td>\n",
       "      <td>Financial Data Services</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>Ensign Group</td>\n",
       "      <td>1849.0</td>\n",
       "      <td>40.5</td>\n",
       "      <td>21301</td>\n",
       "      <td>Health Care</td>\n",
       "      <td>Health Care: Medical Facilities</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>HCP</td>\n",
       "      <td>1848.0</td>\n",
       "      <td>414.2</td>\n",
       "      <td>190</td>\n",
       "      <td>Financials</td>\n",
       "      <td>Real estate</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                             Company  Revenues  Profits  Employees  \\\n",
       "0                            Walmart  500343.0   9862.0    2300000   \n",
       "1                        Exxon Mobil  244363.0  19710.0      71200   \n",
       "2                 Berkshire Hathaway  242137.0  44940.0     377000   \n",
       "3                              Apple  229234.0  48351.0     123000   \n",
       "4                 UnitedHealth Group  201159.0  10558.0     260000   \n",
       "..                               ...       ...      ...        ...   \n",
       "995         SiteOne Landscape Supply    1862.0     54.6       3664   \n",
       "996  Charles River Laboratories Intl    1858.0    123.4      11800   \n",
       "997                        CoreLogic    1851.0    152.2       5900   \n",
       "998                     Ensign Group    1849.0     40.5      21301   \n",
       "999                              HCP    1848.0    414.2        190   \n",
       "\n",
       "                Sector                                  Industry  \n",
       "0            Retailing                     General Merchandisers  \n",
       "1               Energy                        Petroleum Refining  \n",
       "2           Financials  Insurance: Property and Casualty (Stock)  \n",
       "3           Technology               Computers, Office Equipment  \n",
       "4          Health Care   Health Care: Insurance and Managed Care  \n",
       "..                 ...                                       ...  \n",
       "995        Wholesalers                  Wholesalers: Diversified  \n",
       "996        Health Care  Health Care: Pharmacy and Other Services  \n",
       "997  Business Services                   Financial Data Services  \n",
       "998        Health Care           Health Care: Medical Facilities  \n",
       "999         Financials                               Real estate  \n",
       "\n",
       "[1000 rows x 6 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fortune = pd.read_csv(\"fortune1000.csv\")\n",
    "fortune"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Company</th>\n",
       "      <th>Revenues</th>\n",
       "      <th>Profits</th>\n",
       "      <th>Employees</th>\n",
       "      <th>Sector</th>\n",
       "      <th>Industry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Walmart</td>\n",
       "      <td>500343.0</td>\n",
       "      <td>9862.0</td>\n",
       "      <td>2300000</td>\n",
       "      <td>Retailing</td>\n",
       "      <td>General Merchandisers</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Amazon.com</td>\n",
       "      <td>177866.0</td>\n",
       "      <td>3033.0</td>\n",
       "      <td>566000</td>\n",
       "      <td>Retailing</td>\n",
       "      <td>Internet Services and Retailing</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>Costco</td>\n",
       "      <td>129025.0</td>\n",
       "      <td>2679.0</td>\n",
       "      <td>182000</td>\n",
       "      <td>Retailing</td>\n",
       "      <td>General Merchandisers</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>Home Depot</td>\n",
       "      <td>100904.0</td>\n",
       "      <td>8630.0</td>\n",
       "      <td>413000</td>\n",
       "      <td>Retailing</td>\n",
       "      <td>Specialty Retailers: Other</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>Target</td>\n",
       "      <td>71879.0</td>\n",
       "      <td>2934.0</td>\n",
       "      <td>345000</td>\n",
       "      <td>Retailing</td>\n",
       "      <td>General Merchandisers</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       Company  Revenues  Profits  Employees     Sector  \\\n",
       "0      Walmart  500343.0   9862.0    2300000  Retailing   \n",
       "7   Amazon.com  177866.0   3033.0     566000  Retailing   \n",
       "14      Costco  129025.0   2679.0     182000  Retailing   \n",
       "22  Home Depot  100904.0   8630.0     413000  Retailing   \n",
       "38      Target   71879.0   2934.0     345000  Retailing   \n",
       "\n",
       "                           Industry  \n",
       "0             General Merchandisers  \n",
       "7   Internet Services and Retailing  \n",
       "14            General Merchandisers  \n",
       "22       Specialty Retailers: Other  \n",
       "38            General Merchandisers  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "in_retailing = fortune[\"Sector\"] == \"Retailing\"\n",
    "retail_companies = fortune[in_retailing]\n",
    "retail_companies.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     500343.0\n",
       "7     177866.0\n",
       "14    129025.0\n",
       "22    100904.0\n",
       "38     71879.0\n",
       "Name: Revenues, dtype: float64"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "retail_companies[\"Revenues\"].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "21874.714285714286"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "retail_companies[\"Revenues\"].mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "sectors = fortune.groupby(\"Sector\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<pandas.core.groupby.generic.DataFrameGroupBy object at 0x7fe669e5c220>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sectors"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "21"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(sectors)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "21"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fortune[\"Sector\"].nunique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Sector\n",
       "Aerospace & Defense               25\n",
       "Apparel                           14\n",
       "Business Services                 53\n",
       "Chemicals                         33\n",
       "Energy                           107\n",
       "Engineering & Construction        27\n",
       "Financials                       155\n",
       "Food &  Drug Stores               12\n",
       "Food, Beverages & Tobacco         37\n",
       "Health Care                       71\n",
       "Hotels, Restaurants & Leisure     26\n",
       "Household Products                28\n",
       "Industrials                       49\n",
       "Materials                         45\n",
       "Media                             25\n",
       "Motor Vehicles & Parts            19\n",
       "Retailing                         77\n",
       "Technology                       103\n",
       "Telecommunications                10\n",
       "Transportation                    40\n",
       "Wholesalers                       44\n",
       "dtype: int64"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sectors.size()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 9.3 Attributes and Methods on a GroupBy Object"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Aerospace & Defense': [26, 50, 58, 98, 117, 118, 207, 224, 275, 380, 404, 406, 414, 540, 660, 661, 806, 829, 884, 930, 954, 955, 959, 975, 988], 'Apparel': [88, 241, 331, 420, 432, 526, 529, 554, 587, 678, 766, 774, 835, 861], 'Business Services': [142, 160, 187, 199, 201, 221, 235, 242, 253, 295, 325, 358, 364, 423, 462, 465, 486, 493, 497, 499, 502, 510, 528, 567, 577, 584, 591, 599, 604, 618, 649, 686, 691, 692, 700, 702, 712, 720, 738, 744, 771, 802, 810, 825, 879, 888, 894, 895, 898, 905, 922, 972, 997], 'Chemicals': [46, 189, 190, 198, 214, 263, 281, 309, 344, 351, 381, 447, 450, 454, 527, 593, 623, 648, 671, 672, 679, 704, 722, 740, 790, 836, 865, 872, 908, 932, 958, 963, 978], 'Energy': [1, 12, 27, 30, 40, 63, 89, 90, 91, 94, 104, 114, 124, 125, 134, 145, 166, 167, 175, 184, 205, 212, 213, 217, 218, 219, 222, 231, 232, 243, 248, 254, 256, 265, 268, 269, 270, 273, 307, 313, 326, 333, 335, 343, 352, 363, 371, 379, 383, 384, 387, 428, 437, 452, 456, 488, 490, 496, 498, 500, 517, 534, 537, 559, 563, 582, 603, 617, 635, 638, 639, 647, 653, 668, 681, 682, 689, 708, 719, 723, 739, 768, 791, 798, 805, 812, 816, 818, 820, 826, 844, 859, 860, 866, 869, 885, 890, 901, 917, 934, ...], 'Engineering & Construction': [152, 163, 210, 229, 296, 315, 338, 340, 367, 427, 443, 479, 541, 569, 588, 615, 705, 736, 737, 764, 779, 815, 841, 852, 962, 982, 986], 'Financials': [2, 19, 20, 23, 25, 31, 35, 37, 42, 51, 59, 65, 66, 67, 68, 69, 78, 83, 85, 92, 99, 100, 102, 103, 105, 111, 121, 135, 136, 155, 164, 172, 174, 204, 206, 209, 211, 216, 233, 236, 238, 240, 249, 251, 252, 258, 262, 266, 298, 301, 302, 306, 310, 312, 329, 336, 342, 347, 355, 365, 368, 374, 375, 377, 397, 411, 412, 418, 430, 434, 436, 439, 440, 449, 453, 457, 459, 461, 463, 466, 468, 469, 475, 476, 482, 483, 485, 492, 501, 513, 514, 533, 539, 543, 562, 570, 572, 576, 579, 581, ...], 'Food &  Drug Stores': [16, 18, 52, 87, 93, 179, 549, 552, 600, 667, 839, 941], 'Food, Beverages & Tobacco': [44, 47, 79, 86, 95, 107, 113, 116, 153, 181, 215, 225, 274, 320, 322, 357, 361, 378, 382, 385, 417, 445, 477, 480, 511, 538, 575, 611, 628, 633, 683, 694, 717, 734, 759, 900, 937], 'Health Care': [4, 6, 24, 28, 36, 48, 55, 56, 60, 62, 72, 77, 109, 110, 115, 128, 129, 144, 146, 151, 159, 161, 169, 178, 197, 223, 239, 244, 250, 267, 282, 285, 303, 327, 360, 366, 389, 415, 472, 474, 503, 506, 518, 542, 555, 560, 602, 605, 655, 669, 673, 718, 724, 742, 753, 754, 782, 795, 830, 845, 915, 921, 925, 935, 936, 939, 956, 960, 994, 996, 998], 'Hotels, Restaurants & Leisure': [126, 130, 131, 226, 279, 323, 395, 396, 446, 471, 478, 535, 548, 556, 583, 713, 714, 721, 741, 775, 817, 851, 891, 903, 965, 984], 'Household Products': [41, 162, 183, 195, 227, 257, 314, 370, 372, 421, 467, 484, 508, 512, 532, 608, 622, 727, 778, 794, 821, 875, 881, 882, 893, 912, 946, 967], 'Industrials': [17, 64, 76, 96, 101, 139, 148, 154, 177, 203, 255, 292, 341, 346, 359, 413, 419, 444, 546, 571, 601, 616, 619, 620, 626, 627, 631, 634, 664, 687, 730, 731, 750, 776, 803, 813, 827, 850, 853, 854, 857, 864, 878, 887, 938, 943, 951, 966, 981], 'Materials': [123, 150, 193, 245, 261, 276, 304, 311, 337, 393, 398, 399, 403, 409, 426, 435, 441, 455, 460, 516, 522, 524, 564, 594, 595, 596, 606, 609, 614, 624, 641, 662, 663, 685, 695, 707, 729, 756, 781, 786, 833, 837, 945, 957, 974], 'Media': [54, 97, 108, 196, 220, 289, 349, 376, 405, 408, 451, 592, 645, 650, 654, 710, 715, 728, 735, 767, 785, 819, 847, 961, 993], 'Motor Vehicles & Parts': [9, 10, 147, 186, 259, 288, 300, 319, 391, 392, 448, 643, 699, 716, 758, 886, 889, 920, 940], 'Retailing': [0, 7, 14, 22, 38, 39, 71, 84, 119, 122, 133, 137, 138, 156, 171, 173, 180, 182, 208, 230, 234, 247, 271, 272, 277, 278, 280, 287, 293, 294, 297, 316, 321, 328, 332, 334, 339, 362, 390, 422, 424, 433, 438, 458, 464, 470, 504, 507, 509, 545, 547, 580, 589, 610, 612, 621, 644, 665, 680, 698, 732, 745, 746, 770, 777, 792, 822, 846, 855, 856, 858, 880, 909, 926, 971, 989, 992], 'Technology': [3, 21, 29, 33, 34, 45, 57, 61, 75, 81, 106, 132, 143, 149, 157, 158, 188, 191, 194, 200, 228, 260, 284, 290, 291, 305, 308, 353, 373, 388, 400, 402, 410, 416, 431, 442, 481, 491, 494, 505, 515, 519, 523, 525, 536, 544, 550, 551, 553, 557, 558, 573, 578, 585, 586, 597, 636, 646, 656, 666, 674, 696, 697, 703, 709, 726, 752, 755, 763, 769, 780, 783, 787, 788, 797, 799, 807, 823, 824, 828, 834, 842, 843, 849, 862, 868, 871, 874, 876, 892, 897, 902, 919, 924, 927, 931, 944, 948, 969, 970, ...], 'Telecommunications': [8, 15, 32, 73, 165, 202, 324, 473, 520, 907], 'Transportation': [43, 49, 70, 74, 80, 140, 141, 185, 192, 264, 283, 354, 386, 394, 401, 407, 487, 495, 530, 531, 566, 598, 632, 637, 675, 688, 706, 762, 793, 801, 814, 848, 904, 906, 914, 918, 928, 933, 947, 968], 'Wholesalers': [5, 11, 13, 53, 82, 112, 120, 127, 168, 170, 176, 237, 246, 286, 299, 317, 318, 330, 345, 348, 350, 356, 369, 425, 429, 489, 521, 561, 565, 568, 574, 642, 652, 670, 684, 748, 757, 773, 800, 809, 870, 910, 942, 995]}"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sectors.groups"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Aerospace & Defense'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fortune.loc[26, \"Sector\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Company</th>\n",
       "      <th>Revenues</th>\n",
       "      <th>Profits</th>\n",
       "      <th>Employees</th>\n",
       "      <th>Industry</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sector</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Aerospace &amp; Defense</th>\n",
       "      <td>Boeing</td>\n",
       "      <td>93392.0</td>\n",
       "      <td>8197.0</td>\n",
       "      <td>140800</td>\n",
       "      <td>Aerospace and Defense</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Apparel</th>\n",
       "      <td>Nike</td>\n",
       "      <td>34350.0</td>\n",
       "      <td>4240.0</td>\n",
       "      <td>74400</td>\n",
       "      <td>Apparel</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Business Services</th>\n",
       "      <td>ManpowerGroup</td>\n",
       "      <td>21034.0</td>\n",
       "      <td>545.4</td>\n",
       "      <td>29000</td>\n",
       "      <td>Temporary Help</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chemicals</th>\n",
       "      <td>DowDuPont</td>\n",
       "      <td>62683.0</td>\n",
       "      <td>1460.0</td>\n",
       "      <td>98000</td>\n",
       "      <td>Chemicals</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Energy</th>\n",
       "      <td>Exxon Mobil</td>\n",
       "      <td>244363.0</td>\n",
       "      <td>19710.0</td>\n",
       "      <td>71200</td>\n",
       "      <td>Petroleum Refining</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Engineering &amp; Construction</th>\n",
       "      <td>Fluor</td>\n",
       "      <td>19521.0</td>\n",
       "      <td>191.4</td>\n",
       "      <td>56706</td>\n",
       "      <td>Engineering, Construction</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Financials</th>\n",
       "      <td>Berkshire Hathaway</td>\n",
       "      <td>242137.0</td>\n",
       "      <td>44940.0</td>\n",
       "      <td>377000</td>\n",
       "      <td>Insurance: Property and Casualty (Stock)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Food &amp;  Drug Stores</th>\n",
       "      <td>Kroger</td>\n",
       "      <td>122662.0</td>\n",
       "      <td>1907.0</td>\n",
       "      <td>449000</td>\n",
       "      <td>Food and Drug Stores</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Food, Beverages &amp; Tobacco</th>\n",
       "      <td>PepsiCo</td>\n",
       "      <td>63525.0</td>\n",
       "      <td>4857.0</td>\n",
       "      <td>263000</td>\n",
       "      <td>Food Consumer Products</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Health Care</th>\n",
       "      <td>UnitedHealth Group</td>\n",
       "      <td>201159.0</td>\n",
       "      <td>10558.0</td>\n",
       "      <td>260000</td>\n",
       "      <td>Health Care: Insurance and Managed Care</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hotels, Restaurants &amp; Leisure</th>\n",
       "      <td>Marriott International</td>\n",
       "      <td>22894.0</td>\n",
       "      <td>1372.0</td>\n",
       "      <td>177000</td>\n",
       "      <td>Hotels, Casinos, Resorts</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Household Products</th>\n",
       "      <td>Procter &amp; Gamble</td>\n",
       "      <td>66217.0</td>\n",
       "      <td>15326.0</td>\n",
       "      <td>95000</td>\n",
       "      <td>Household and Personal Products</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Industrials</th>\n",
       "      <td>General Electric</td>\n",
       "      <td>122274.0</td>\n",
       "      <td>-5786.0</td>\n",
       "      <td>313000</td>\n",
       "      <td>Industrial Machinery</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Materials</th>\n",
       "      <td>International Paper</td>\n",
       "      <td>23302.0</td>\n",
       "      <td>2144.0</td>\n",
       "      <td>56000</td>\n",
       "      <td>Packaging, Containers</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Media</th>\n",
       "      <td>Disney</td>\n",
       "      <td>55137.0</td>\n",
       "      <td>8980.0</td>\n",
       "      <td>199000</td>\n",
       "      <td>Entertainment</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Motor Vehicles &amp; Parts</th>\n",
       "      <td>General Motors</td>\n",
       "      <td>157311.0</td>\n",
       "      <td>-3864.0</td>\n",
       "      <td>180000</td>\n",
       "      <td>Motor Vehicles and Parts</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Retailing</th>\n",
       "      <td>Walmart</td>\n",
       "      <td>500343.0</td>\n",
       "      <td>9862.0</td>\n",
       "      <td>2300000</td>\n",
       "      <td>General Merchandisers</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Technology</th>\n",
       "      <td>Apple</td>\n",
       "      <td>229234.0</td>\n",
       "      <td>48351.0</td>\n",
       "      <td>123000</td>\n",
       "      <td>Computers, Office Equipment</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Telecommunications</th>\n",
       "      <td>AT&amp;T</td>\n",
       "      <td>160546.0</td>\n",
       "      <td>29450.0</td>\n",
       "      <td>254000</td>\n",
       "      <td>Telecommunications</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Transportation</th>\n",
       "      <td>UPS</td>\n",
       "      <td>65872.0</td>\n",
       "      <td>4910.0</td>\n",
       "      <td>346415</td>\n",
       "      <td>Mail, Package, and Freight Delivery</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Wholesalers</th>\n",
       "      <td>McKesson</td>\n",
       "      <td>198533.0</td>\n",
       "      <td>5070.0</td>\n",
       "      <td>64500</td>\n",
       "      <td>Wholesalers: Health Care</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                              Company  Revenues  Profits  \\\n",
       "Sector                                                                     \n",
       "Aerospace & Defense                            Boeing   93392.0   8197.0   \n",
       "Apparel                                          Nike   34350.0   4240.0   \n",
       "Business Services                       ManpowerGroup   21034.0    545.4   \n",
       "Chemicals                                   DowDuPont   62683.0   1460.0   \n",
       "Energy                                    Exxon Mobil  244363.0  19710.0   \n",
       "Engineering & Construction                      Fluor   19521.0    191.4   \n",
       "Financials                         Berkshire Hathaway  242137.0  44940.0   \n",
       "Food &  Drug Stores                            Kroger  122662.0   1907.0   \n",
       "Food, Beverages & Tobacco                     PepsiCo   63525.0   4857.0   \n",
       "Health Care                        UnitedHealth Group  201159.0  10558.0   \n",
       "Hotels, Restaurants & Leisure  Marriott International   22894.0   1372.0   \n",
       "Household Products                   Procter & Gamble   66217.0  15326.0   \n",
       "Industrials                          General Electric  122274.0  -5786.0   \n",
       "Materials                         International Paper   23302.0   2144.0   \n",
       "Media                                          Disney   55137.0   8980.0   \n",
       "Motor Vehicles & Parts                 General Motors  157311.0  -3864.0   \n",
       "Retailing                                     Walmart  500343.0   9862.0   \n",
       "Technology                                      Apple  229234.0  48351.0   \n",
       "Telecommunications                               AT&T  160546.0  29450.0   \n",
       "Transportation                                    UPS   65872.0   4910.0   \n",
       "Wholesalers                                  McKesson  198533.0   5070.0   \n",
       "\n",
       "                               Employees  \\\n",
       "Sector                                     \n",
       "Aerospace & Defense               140800   \n",
       "Apparel                            74400   \n",
       "Business Services                  29000   \n",
       "Chemicals                          98000   \n",
       "Energy                             71200   \n",
       "Engineering & Construction         56706   \n",
       "Financials                        377000   \n",
       "Food &  Drug Stores               449000   \n",
       "Food, Beverages & Tobacco         263000   \n",
       "Health Care                       260000   \n",
       "Hotels, Restaurants & Leisure     177000   \n",
       "Household Products                 95000   \n",
       "Industrials                       313000   \n",
       "Materials                          56000   \n",
       "Media                             199000   \n",
       "Motor Vehicles & Parts            180000   \n",
       "Retailing                        2300000   \n",
       "Technology                        123000   \n",
       "Telecommunications                254000   \n",
       "Transportation                    346415   \n",
       "Wholesalers                        64500   \n",
       "\n",
       "                                                               Industry  \n",
       "Sector                                                                   \n",
       "Aerospace & Defense                               Aerospace and Defense  \n",
       "Apparel                                                         Apparel  \n",
       "Business Services                                        Temporary Help  \n",
       "Chemicals                                                     Chemicals  \n",
       "Energy                                               Petroleum Refining  \n",
       "Engineering & Construction                    Engineering, Construction  \n",
       "Financials                     Insurance: Property and Casualty (Stock)  \n",
       "Food &  Drug Stores                                Food and Drug Stores  \n",
       "Food, Beverages & Tobacco                        Food Consumer Products  \n",
       "Health Care                     Health Care: Insurance and Managed Care  \n",
       "Hotels, Restaurants & Leisure                  Hotels, Casinos, Resorts  \n",
       "Household Products                      Household and Personal Products  \n",
       "Industrials                                        Industrial Machinery  \n",
       "Materials                                         Packaging, Containers  \n",
       "Media                                                     Entertainment  \n",
       "Motor Vehicles & Parts                         Motor Vehicles and Parts  \n",
       "Retailing                                         General Merchandisers  \n",
       "Technology                                  Computers, Office Equipment  \n",
       "Telecommunications                                   Telecommunications  \n",
       "Transportation                      Mail, Package, and Freight Delivery  \n",
       "Wholesalers                                    Wholesalers: Health Care  "
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sectors.first()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Company</th>\n",
       "      <th>Revenues</th>\n",
       "      <th>Profits</th>\n",
       "      <th>Employees</th>\n",
       "      <th>Industry</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sector</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Aerospace &amp; Defense</th>\n",
       "      <td>Aerojet Rocketdyne Holdings</td>\n",
       "      <td>1877.0</td>\n",
       "      <td>-9.2</td>\n",
       "      <td>5157</td>\n",
       "      <td>Aerospace and Defense</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Apparel</th>\n",
       "      <td>Wolverine World Wide</td>\n",
       "      <td>2350.0</td>\n",
       "      <td>0.3</td>\n",
       "      <td>3700</td>\n",
       "      <td>Apparel</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Business Services</th>\n",
       "      <td>CoreLogic</td>\n",
       "      <td>1851.0</td>\n",
       "      <td>152.2</td>\n",
       "      <td>5900</td>\n",
       "      <td>Financial Data Services</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chemicals</th>\n",
       "      <td>Stepan</td>\n",
       "      <td>1925.0</td>\n",
       "      <td>91.6</td>\n",
       "      <td>2096</td>\n",
       "      <td>Chemicals</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Energy</th>\n",
       "      <td>Superior Energy Services</td>\n",
       "      <td>1874.0</td>\n",
       "      <td>-205.9</td>\n",
       "      <td>6400</td>\n",
       "      <td>Oil and Gas Equipment, Services</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Engineering &amp; Construction</th>\n",
       "      <td>TopBuild</td>\n",
       "      <td>1906.0</td>\n",
       "      <td>158.1</td>\n",
       "      <td>8400</td>\n",
       "      <td>Engineering, Construction</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Financials</th>\n",
       "      <td>HCP</td>\n",
       "      <td>1848.0</td>\n",
       "      <td>414.2</td>\n",
       "      <td>190</td>\n",
       "      <td>Real estate</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Food &amp;  Drug Stores</th>\n",
       "      <td>Freds</td>\n",
       "      <td>2064.0</td>\n",
       "      <td>-140.3</td>\n",
       "      <td>7324</td>\n",
       "      <td>Food and Drug Stores</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Food, Beverages &amp; Tobacco</th>\n",
       "      <td>Universal</td>\n",
       "      <td>2071.0</td>\n",
       "      <td>106.3</td>\n",
       "      <td>24000</td>\n",
       "      <td>Tobacco</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Health Care</th>\n",
       "      <td>Ensign Group</td>\n",
       "      <td>1849.0</td>\n",
       "      <td>40.5</td>\n",
       "      <td>21301</td>\n",
       "      <td>Health Care: Medical Facilities</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hotels, Restaurants &amp; Leisure</th>\n",
       "      <td>Vail Resorts</td>\n",
       "      <td>1907.0</td>\n",
       "      <td>210.6</td>\n",
       "      <td>20150</td>\n",
       "      <td>Hotels, Casinos, Resorts</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Household Products</th>\n",
       "      <td>ACCO Brands</td>\n",
       "      <td>1949.0</td>\n",
       "      <td>131.7</td>\n",
       "      <td>6620</td>\n",
       "      <td>Home Equipment, Furnishings</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Industrials</th>\n",
       "      <td>Rexnord</td>\n",
       "      <td>1918.0</td>\n",
       "      <td>74.1</td>\n",
       "      <td>8000</td>\n",
       "      <td>Industrial Machinery</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Materials</th>\n",
       "      <td>Summit Materials</td>\n",
       "      <td>1933.0</td>\n",
       "      <td>121.8</td>\n",
       "      <td>6000</td>\n",
       "      <td>Building Materials, Glass</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Media</th>\n",
       "      <td>Tribune Media</td>\n",
       "      <td>1867.0</td>\n",
       "      <td>194.1</td>\n",
       "      <td>6000</td>\n",
       "      <td>Entertainment</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Motor Vehicles &amp; Parts</th>\n",
       "      <td>Tower International</td>\n",
       "      <td>2066.0</td>\n",
       "      <td>47.6</td>\n",
       "      <td>7600</td>\n",
       "      <td>Motor Vehicles and Parts</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Retailing</th>\n",
       "      <td>Childrens Place</td>\n",
       "      <td>1870.0</td>\n",
       "      <td>84.7</td>\n",
       "      <td>9800</td>\n",
       "      <td>Specialty Retailers: Apparel</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Technology</th>\n",
       "      <td>VeriFone Systems</td>\n",
       "      <td>1871.0</td>\n",
       "      <td>-173.8</td>\n",
       "      <td>5600</td>\n",
       "      <td>Financial Data Services</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Telecommunications</th>\n",
       "      <td>Zayo Group Holdings</td>\n",
       "      <td>2200.0</td>\n",
       "      <td>85.7</td>\n",
       "      <td>3794</td>\n",
       "      <td>Telecommunications</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Transportation</th>\n",
       "      <td>Echo Global Logistics</td>\n",
       "      <td>1943.0</td>\n",
       "      <td>12.6</td>\n",
       "      <td>2453</td>\n",
       "      <td>Transportation and Logistics</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Wholesalers</th>\n",
       "      <td>SiteOne Landscape Supply</td>\n",
       "      <td>1862.0</td>\n",
       "      <td>54.6</td>\n",
       "      <td>3664</td>\n",
       "      <td>Wholesalers: Diversified</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                   Company  Revenues  Profits  \\\n",
       "Sector                                                                          \n",
       "Aerospace & Defense            Aerojet Rocketdyne Holdings    1877.0     -9.2   \n",
       "Apparel                               Wolverine World Wide    2350.0      0.3   \n",
       "Business Services                                CoreLogic    1851.0    152.2   \n",
       "Chemicals                                           Stepan    1925.0     91.6   \n",
       "Energy                            Superior Energy Services    1874.0   -205.9   \n",
       "Engineering & Construction                        TopBuild    1906.0    158.1   \n",
       "Financials                                             HCP    1848.0    414.2   \n",
       "Food &  Drug Stores                                  Freds    2064.0   -140.3   \n",
       "Food, Beverages & Tobacco                        Universal    2071.0    106.3   \n",
       "Health Care                                   Ensign Group    1849.0     40.5   \n",
       "Hotels, Restaurants & Leisure                 Vail Resorts    1907.0    210.6   \n",
       "Household Products                             ACCO Brands    1949.0    131.7   \n",
       "Industrials                                        Rexnord    1918.0     74.1   \n",
       "Materials                                 Summit Materials    1933.0    121.8   \n",
       "Media                                        Tribune Media    1867.0    194.1   \n",
       "Motor Vehicles & Parts                 Tower International    2066.0     47.6   \n",
       "Retailing                                  Childrens Place    1870.0     84.7   \n",
       "Technology                                VeriFone Systems    1871.0   -173.8   \n",
       "Telecommunications                     Zayo Group Holdings    2200.0     85.7   \n",
       "Transportation                       Echo Global Logistics    1943.0     12.6   \n",
       "Wholesalers                       SiteOne Landscape Supply    1862.0     54.6   \n",
       "\n",
       "                               Employees                         Industry  \n",
       "Sector                                                                     \n",
       "Aerospace & Defense                 5157            Aerospace and Defense  \n",
       "Apparel                             3700                          Apparel  \n",
       "Business Services                   5900          Financial Data Services  \n",
       "Chemicals                           2096                        Chemicals  \n",
       "Energy                              6400  Oil and Gas Equipment, Services  \n",
       "Engineering & Construction          8400        Engineering, Construction  \n",
       "Financials                           190                      Real estate  \n",
       "Food &  Drug Stores                 7324             Food and Drug Stores  \n",
       "Food, Beverages & Tobacco          24000                          Tobacco  \n",
       "Health Care                        21301  Health Care: Medical Facilities  \n",
       "Hotels, Restaurants & Leisure      20150         Hotels, Casinos, Resorts  \n",
       "Household Products                  6620      Home Equipment, Furnishings  \n",
       "Industrials                         8000             Industrial Machinery  \n",
       "Materials                           6000        Building Materials, Glass  \n",
       "Media                               6000                    Entertainment  \n",
       "Motor Vehicles & Parts              7600         Motor Vehicles and Parts  \n",
       "Retailing                           9800     Specialty Retailers: Apparel  \n",
       "Technology                          5600          Financial Data Services  \n",
       "Telecommunications                  3794               Telecommunications  \n",
       "Transportation                      2453     Transportation and Logistics  \n",
       "Wholesalers                         3664         Wholesalers: Diversified  "
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sectors.last()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Company</th>\n",
       "      <th>Revenues</th>\n",
       "      <th>Profits</th>\n",
       "      <th>Employees</th>\n",
       "      <th>Industry</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sector</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Aerospace &amp; Defense</th>\n",
       "      <td>Boeing</td>\n",
       "      <td>93392.0</td>\n",
       "      <td>8197.0</td>\n",
       "      <td>140800</td>\n",
       "      <td>Aerospace and Defense</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Apparel</th>\n",
       "      <td>Nike</td>\n",
       "      <td>34350.0</td>\n",
       "      <td>4240.0</td>\n",
       "      <td>74400</td>\n",
       "      <td>Apparel</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Business Services</th>\n",
       "      <td>ManpowerGroup</td>\n",
       "      <td>21034.0</td>\n",
       "      <td>545.4</td>\n",
       "      <td>29000</td>\n",
       "      <td>Temporary Help</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chemicals</th>\n",
       "      <td>DowDuPont</td>\n",
       "      <td>62683.0</td>\n",
       "      <td>1460.0</td>\n",
       "      <td>98000</td>\n",
       "      <td>Chemicals</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Energy</th>\n",
       "      <td>Exxon Mobil</td>\n",
       "      <td>244363.0</td>\n",
       "      <td>19710.0</td>\n",
       "      <td>71200</td>\n",
       "      <td>Petroleum Refining</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Engineering &amp; Construction</th>\n",
       "      <td>Fluor</td>\n",
       "      <td>19521.0</td>\n",
       "      <td>191.4</td>\n",
       "      <td>56706</td>\n",
       "      <td>Engineering, Construction</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Financials</th>\n",
       "      <td>Berkshire Hathaway</td>\n",
       "      <td>242137.0</td>\n",
       "      <td>44940.0</td>\n",
       "      <td>377000</td>\n",
       "      <td>Insurance: Property and Casualty (Stock)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Food &amp;  Drug Stores</th>\n",
       "      <td>Kroger</td>\n",
       "      <td>122662.0</td>\n",
       "      <td>1907.0</td>\n",
       "      <td>449000</td>\n",
       "      <td>Food and Drug Stores</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Food, Beverages &amp; Tobacco</th>\n",
       "      <td>PepsiCo</td>\n",
       "      <td>63525.0</td>\n",
       "      <td>4857.0</td>\n",
       "      <td>263000</td>\n",
       "      <td>Food Consumer Products</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Health Care</th>\n",
       "      <td>UnitedHealth Group</td>\n",
       "      <td>201159.0</td>\n",
       "      <td>10558.0</td>\n",
       "      <td>260000</td>\n",
       "      <td>Health Care: Insurance and Managed Care</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hotels, Restaurants &amp; Leisure</th>\n",
       "      <td>Marriott International</td>\n",
       "      <td>22894.0</td>\n",
       "      <td>1372.0</td>\n",
       "      <td>177000</td>\n",
       "      <td>Hotels, Casinos, Resorts</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Household Products</th>\n",
       "      <td>Procter &amp; Gamble</td>\n",
       "      <td>66217.0</td>\n",
       "      <td>15326.0</td>\n",
       "      <td>95000</td>\n",
       "      <td>Household and Personal Products</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Industrials</th>\n",
       "      <td>General Electric</td>\n",
       "      <td>122274.0</td>\n",
       "      <td>-5786.0</td>\n",
       "      <td>313000</td>\n",
       "      <td>Industrial Machinery</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Materials</th>\n",
       "      <td>International Paper</td>\n",
       "      <td>23302.0</td>\n",
       "      <td>2144.0</td>\n",
       "      <td>56000</td>\n",
       "      <td>Packaging, Containers</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Media</th>\n",
       "      <td>Disney</td>\n",
       "      <td>55137.0</td>\n",
       "      <td>8980.0</td>\n",
       "      <td>199000</td>\n",
       "      <td>Entertainment</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Motor Vehicles &amp; Parts</th>\n",
       "      <td>General Motors</td>\n",
       "      <td>157311.0</td>\n",
       "      <td>-3864.0</td>\n",
       "      <td>180000</td>\n",
       "      <td>Motor Vehicles and Parts</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Retailing</th>\n",
       "      <td>Walmart</td>\n",
       "      <td>500343.0</td>\n",
       "      <td>9862.0</td>\n",
       "      <td>2300000</td>\n",
       "      <td>General Merchandisers</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Technology</th>\n",
       "      <td>Apple</td>\n",
       "      <td>229234.0</td>\n",
       "      <td>48351.0</td>\n",
       "      <td>123000</td>\n",
       "      <td>Computers, Office Equipment</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Telecommunications</th>\n",
       "      <td>AT&amp;T</td>\n",
       "      <td>160546.0</td>\n",
       "      <td>29450.0</td>\n",
       "      <td>254000</td>\n",
       "      <td>Telecommunications</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Transportation</th>\n",
       "      <td>UPS</td>\n",
       "      <td>65872.0</td>\n",
       "      <td>4910.0</td>\n",
       "      <td>346415</td>\n",
       "      <td>Mail, Package, and Freight Delivery</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Wholesalers</th>\n",
       "      <td>McKesson</td>\n",
       "      <td>198533.0</td>\n",
       "      <td>5070.0</td>\n",
       "      <td>64500</td>\n",
       "      <td>Wholesalers: Health Care</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                              Company  Revenues  Profits  \\\n",
       "Sector                                                                     \n",
       "Aerospace & Defense                            Boeing   93392.0   8197.0   \n",
       "Apparel                                          Nike   34350.0   4240.0   \n",
       "Business Services                       ManpowerGroup   21034.0    545.4   \n",
       "Chemicals                                   DowDuPont   62683.0   1460.0   \n",
       "Energy                                    Exxon Mobil  244363.0  19710.0   \n",
       "Engineering & Construction                      Fluor   19521.0    191.4   \n",
       "Financials                         Berkshire Hathaway  242137.0  44940.0   \n",
       "Food &  Drug Stores                            Kroger  122662.0   1907.0   \n",
       "Food, Beverages & Tobacco                     PepsiCo   63525.0   4857.0   \n",
       "Health Care                        UnitedHealth Group  201159.0  10558.0   \n",
       "Hotels, Restaurants & Leisure  Marriott International   22894.0   1372.0   \n",
       "Household Products                   Procter & Gamble   66217.0  15326.0   \n",
       "Industrials                          General Electric  122274.0  -5786.0   \n",
       "Materials                         International Paper   23302.0   2144.0   \n",
       "Media                                          Disney   55137.0   8980.0   \n",
       "Motor Vehicles & Parts                 General Motors  157311.0  -3864.0   \n",
       "Retailing                                     Walmart  500343.0   9862.0   \n",
       "Technology                                      Apple  229234.0  48351.0   \n",
       "Telecommunications                               AT&T  160546.0  29450.0   \n",
       "Transportation                                    UPS   65872.0   4910.0   \n",
       "Wholesalers                                  McKesson  198533.0   5070.0   \n",
       "\n",
       "                               Employees  \\\n",
       "Sector                                     \n",
       "Aerospace & Defense               140800   \n",
       "Apparel                            74400   \n",
       "Business Services                  29000   \n",
       "Chemicals                          98000   \n",
       "Energy                             71200   \n",
       "Engineering & Construction         56706   \n",
       "Financials                        377000   \n",
       "Food &  Drug Stores               449000   \n",
       "Food, Beverages & Tobacco         263000   \n",
       "Health Care                       260000   \n",
       "Hotels, Restaurants & Leisure     177000   \n",
       "Household Products                 95000   \n",
       "Industrials                       313000   \n",
       "Materials                          56000   \n",
       "Media                             199000   \n",
       "Motor Vehicles & Parts            180000   \n",
       "Retailing                        2300000   \n",
       "Technology                        123000   \n",
       "Telecommunications                254000   \n",
       "Transportation                    346415   \n",
       "Wholesalers                        64500   \n",
       "\n",
       "                                                               Industry  \n",
       "Sector                                                                   \n",
       "Aerospace & Defense                               Aerospace and Defense  \n",
       "Apparel                                                         Apparel  \n",
       "Business Services                                        Temporary Help  \n",
       "Chemicals                                                     Chemicals  \n",
       "Energy                                               Petroleum Refining  \n",
       "Engineering & Construction                    Engineering, Construction  \n",
       "Financials                     Insurance: Property and Casualty (Stock)  \n",
       "Food &  Drug Stores                                Food and Drug Stores  \n",
       "Food, Beverages & Tobacco                        Food Consumer Products  \n",
       "Health Care                     Health Care: Insurance and Managed Care  \n",
       "Hotels, Restaurants & Leisure                  Hotels, Casinos, Resorts  \n",
       "Household Products                      Household and Personal Products  \n",
       "Industrials                                        Industrial Machinery  \n",
       "Materials                                         Packaging, Containers  \n",
       "Media                                                     Entertainment  \n",
       "Motor Vehicles & Parts                         Motor Vehicles and Parts  \n",
       "Retailing                                         General Merchandisers  \n",
       "Technology                                  Computers, Office Equipment  \n",
       "Telecommunications                                   Telecommunications  \n",
       "Transportation                      Mail, Package, and Freight Delivery  \n",
       "Wholesalers                                    Wholesalers: Health Care  "
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sectors.nth(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Company</th>\n",
       "      <th>Revenues</th>\n",
       "      <th>Profits</th>\n",
       "      <th>Employees</th>\n",
       "      <th>Industry</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sector</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Aerospace &amp; Defense</th>\n",
       "      <td>General Dynamics</td>\n",
       "      <td>30973.0</td>\n",
       "      <td>2912.0</td>\n",
       "      <td>98600</td>\n",
       "      <td>Aerospace and Defense</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Apparel</th>\n",
       "      <td>Ralph Lauren</td>\n",
       "      <td>6653.0</td>\n",
       "      <td>-99.3</td>\n",
       "      <td>18250</td>\n",
       "      <td>Apparel</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Business Services</th>\n",
       "      <td>Aramark</td>\n",
       "      <td>14604.0</td>\n",
       "      <td>373.9</td>\n",
       "      <td>215000</td>\n",
       "      <td>Diversified Outsourcing Services</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chemicals</th>\n",
       "      <td>Monsanto</td>\n",
       "      <td>14640.0</td>\n",
       "      <td>2260.0</td>\n",
       "      <td>21900</td>\n",
       "      <td>Chemicals</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Energy</th>\n",
       "      <td>Valero Energy</td>\n",
       "      <td>88407.0</td>\n",
       "      <td>4065.0</td>\n",
       "      <td>10015</td>\n",
       "      <td>Petroleum Refining</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Engineering &amp; Construction</th>\n",
       "      <td>Lennar</td>\n",
       "      <td>12646.0</td>\n",
       "      <td>810.5</td>\n",
       "      <td>9111</td>\n",
       "      <td>Homebuilders</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Financials</th>\n",
       "      <td>Bank of America Corp.</td>\n",
       "      <td>100264.0</td>\n",
       "      <td>18232.0</td>\n",
       "      <td>209376</td>\n",
       "      <td>Commercial Banks</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Food &amp;  Drug Stores</th>\n",
       "      <td>Publix Super Markets</td>\n",
       "      <td>34837.0</td>\n",
       "      <td>2291.9</td>\n",
       "      <td>193000</td>\n",
       "      <td>Food and Drug Stores</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Food, Beverages &amp; Tobacco</th>\n",
       "      <td>Coca-Cola</td>\n",
       "      <td>35410.0</td>\n",
       "      <td>1248.0</td>\n",
       "      <td>61800</td>\n",
       "      <td>Beverages</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Health Care</th>\n",
       "      <td>Anthem</td>\n",
       "      <td>90040.0</td>\n",
       "      <td>3842.8</td>\n",
       "      <td>56000</td>\n",
       "      <td>Health Care: Insurance and Managed Care</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hotels, Restaurants &amp; Leisure</th>\n",
       "      <td>Las Vegas Sands</td>\n",
       "      <td>12882.0</td>\n",
       "      <td>2806.0</td>\n",
       "      <td>50500</td>\n",
       "      <td>Hotels, Casinos, Resorts</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Household Products</th>\n",
       "      <td>Newell Brands</td>\n",
       "      <td>14742.0</td>\n",
       "      <td>2748.8</td>\n",
       "      <td>49000</td>\n",
       "      <td>Home Equipment, Furnishings</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Industrials</th>\n",
       "      <td>3M</td>\n",
       "      <td>31657.0</td>\n",
       "      <td>4858.0</td>\n",
       "      <td>91536</td>\n",
       "      <td>Miscellaneous</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Materials</th>\n",
       "      <td>United States Steel</td>\n",
       "      <td>12250.0</td>\n",
       "      <td>387.0</td>\n",
       "      <td>29200</td>\n",
       "      <td>Metals</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Media</th>\n",
       "      <td>CBS</td>\n",
       "      <td>14710.0</td>\n",
       "      <td>357.0</td>\n",
       "      <td>14715</td>\n",
       "      <td>Entertainment</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Motor Vehicles &amp; Parts</th>\n",
       "      <td>Goodyear Tire &amp; Rubber</td>\n",
       "      <td>15377.0</td>\n",
       "      <td>346.0</td>\n",
       "      <td>64000</td>\n",
       "      <td>Motor Vehicles and Parts</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Retailing</th>\n",
       "      <td>Home Depot</td>\n",
       "      <td>100904.0</td>\n",
       "      <td>8630.0</td>\n",
       "      <td>413000</td>\n",
       "      <td>Specialty Retailers: Other</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Technology</th>\n",
       "      <td>IBM</td>\n",
       "      <td>79139.0</td>\n",
       "      <td>5753.0</td>\n",
       "      <td>397800</td>\n",
       "      <td>Information Technology Services</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Telecommunications</th>\n",
       "      <td>Charter Communications</td>\n",
       "      <td>41581.0</td>\n",
       "      <td>9895.0</td>\n",
       "      <td>94800</td>\n",
       "      <td>Telecommunications</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Transportation</th>\n",
       "      <td>Delta Air Lines</td>\n",
       "      <td>41244.0</td>\n",
       "      <td>3577.0</td>\n",
       "      <td>86564</td>\n",
       "      <td>Airlines</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Wholesalers</th>\n",
       "      <td>Sysco</td>\n",
       "      <td>55371.0</td>\n",
       "      <td>1142.5</td>\n",
       "      <td>66500</td>\n",
       "      <td>Wholesalers: Food and Grocery</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                              Company  Revenues  Profits  \\\n",
       "Sector                                                                     \n",
       "Aerospace & Defense                  General Dynamics   30973.0   2912.0   \n",
       "Apparel                                  Ralph Lauren    6653.0    -99.3   \n",
       "Business Services                             Aramark   14604.0    373.9   \n",
       "Chemicals                                    Monsanto   14640.0   2260.0   \n",
       "Energy                                  Valero Energy   88407.0   4065.0   \n",
       "Engineering & Construction                     Lennar   12646.0    810.5   \n",
       "Financials                      Bank of America Corp.  100264.0  18232.0   \n",
       "Food &  Drug Stores              Publix Super Markets   34837.0   2291.9   \n",
       "Food, Beverages & Tobacco                   Coca-Cola   35410.0   1248.0   \n",
       "Health Care                                    Anthem   90040.0   3842.8   \n",
       "Hotels, Restaurants & Leisure         Las Vegas Sands   12882.0   2806.0   \n",
       "Household Products                      Newell Brands   14742.0   2748.8   \n",
       "Industrials                                        3M   31657.0   4858.0   \n",
       "Materials                         United States Steel   12250.0    387.0   \n",
       "Media                                             CBS   14710.0    357.0   \n",
       "Motor Vehicles & Parts         Goodyear Tire & Rubber   15377.0    346.0   \n",
       "Retailing                                  Home Depot  100904.0   8630.0   \n",
       "Technology                                        IBM   79139.0   5753.0   \n",
       "Telecommunications             Charter Communications   41581.0   9895.0   \n",
       "Transportation                        Delta Air Lines   41244.0   3577.0   \n",
       "Wholesalers                                     Sysco   55371.0   1142.5   \n",
       "\n",
       "                               Employees  \\\n",
       "Sector                                     \n",
       "Aerospace & Defense                98600   \n",
       "Apparel                            18250   \n",
       "Business Services                 215000   \n",
       "Chemicals                          21900   \n",
       "Energy                             10015   \n",
       "Engineering & Construction          9111   \n",
       "Financials                        209376   \n",
       "Food &  Drug Stores               193000   \n",
       "Food, Beverages & Tobacco          61800   \n",
       "Health Care                        56000   \n",
       "Hotels, Restaurants & Leisure      50500   \n",
       "Household Products                 49000   \n",
       "Industrials                        91536   \n",
       "Materials                          29200   \n",
       "Media                              14715   \n",
       "Motor Vehicles & Parts             64000   \n",
       "Retailing                         413000   \n",
       "Technology                        397800   \n",
       "Telecommunications                 94800   \n",
       "Transportation                     86564   \n",
       "Wholesalers                        66500   \n",
       "\n",
       "                                                              Industry  \n",
       "Sector                                                                  \n",
       "Aerospace & Defense                              Aerospace and Defense  \n",
       "Apparel                                                        Apparel  \n",
       "Business Services                     Diversified Outsourcing Services  \n",
       "Chemicals                                                    Chemicals  \n",
       "Energy                                              Petroleum Refining  \n",
       "Engineering & Construction                                Homebuilders  \n",
       "Financials                                            Commercial Banks  \n",
       "Food &  Drug Stores                               Food and Drug Stores  \n",
       "Food, Beverages & Tobacco                                    Beverages  \n",
       "Health Care                    Health Care: Insurance and Managed Care  \n",
       "Hotels, Restaurants & Leisure                 Hotels, Casinos, Resorts  \n",
       "Household Products                         Home Equipment, Furnishings  \n",
       "Industrials                                              Miscellaneous  \n",
       "Materials                                                       Metals  \n",
       "Media                                                    Entertainment  \n",
       "Motor Vehicles & Parts                        Motor Vehicles and Parts  \n",
       "Retailing                                   Specialty Retailers: Other  \n",
       "Technology                             Information Technology Services  \n",
       "Telecommunications                                  Telecommunications  \n",
       "Transportation                                                Airlines  \n",
       "Wholesalers                              Wholesalers: Food and Grocery  "
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sectors.nth(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Company</th>\n",
       "      <th>Revenues</th>\n",
       "      <th>Profits</th>\n",
       "      <th>Employees</th>\n",
       "      <th>Sector</th>\n",
       "      <th>Industry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>Nike</td>\n",
       "      <td>34350.0</td>\n",
       "      <td>4240.0</td>\n",
       "      <td>74400</td>\n",
       "      <td>Apparel</td>\n",
       "      <td>Apparel</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>241</th>\n",
       "      <td>VF</td>\n",
       "      <td>12400.0</td>\n",
       "      <td>614.9</td>\n",
       "      <td>69000</td>\n",
       "      <td>Apparel</td>\n",
       "      <td>Apparel</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>331</th>\n",
       "      <td>PVH</td>\n",
       "      <td>8915.0</td>\n",
       "      <td>537.8</td>\n",
       "      <td>28050</td>\n",
       "      <td>Apparel</td>\n",
       "      <td>Apparel</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>420</th>\n",
       "      <td>Ralph Lauren</td>\n",
       "      <td>6653.0</td>\n",
       "      <td>-99.3</td>\n",
       "      <td>18250</td>\n",
       "      <td>Apparel</td>\n",
       "      <td>Apparel</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>432</th>\n",
       "      <td>Hanesbrands</td>\n",
       "      <td>6478.0</td>\n",
       "      <td>61.9</td>\n",
       "      <td>67200</td>\n",
       "      <td>Apparel</td>\n",
       "      <td>Apparel</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Company  Revenues  Profits  Employees   Sector Industry\n",
       "88           Nike   34350.0   4240.0      74400  Apparel  Apparel\n",
       "241            VF   12400.0    614.9      69000  Apparel  Apparel\n",
       "331           PVH    8915.0    537.8      28050  Apparel  Apparel\n",
       "420  Ralph Lauren    6653.0    -99.3      18250  Apparel  Apparel\n",
       "432   Hanesbrands    6478.0     61.9      67200  Apparel  Apparel"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fortune[fortune[\"Sector\"] == \"Apparel\"].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Company</th>\n",
       "      <th>Revenues</th>\n",
       "      <th>Profits</th>\n",
       "      <th>Employees</th>\n",
       "      <th>Sector</th>\n",
       "      <th>Industry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Walmart</td>\n",
       "      <td>500343.0</td>\n",
       "      <td>9862.0</td>\n",
       "      <td>2300000</td>\n",
       "      <td>Retailing</td>\n",
       "      <td>General Merchandisers</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Exxon Mobil</td>\n",
       "      <td>244363.0</td>\n",
       "      <td>19710.0</td>\n",
       "      <td>71200</td>\n",
       "      <td>Energy</td>\n",
       "      <td>Petroleum Refining</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Berkshire Hathaway</td>\n",
       "      <td>242137.0</td>\n",
       "      <td>44940.0</td>\n",
       "      <td>377000</td>\n",
       "      <td>Financials</td>\n",
       "      <td>Insurance: Property and Casualty (Stock)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Apple</td>\n",
       "      <td>229234.0</td>\n",
       "      <td>48351.0</td>\n",
       "      <td>123000</td>\n",
       "      <td>Technology</td>\n",
       "      <td>Computers, Office Equipment</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>UnitedHealth Group</td>\n",
       "      <td>201159.0</td>\n",
       "      <td>10558.0</td>\n",
       "      <td>260000</td>\n",
       "      <td>Health Care</td>\n",
       "      <td>Health Care: Insurance and Managed Care</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>McKesson</td>\n",
       "      <td>198533.0</td>\n",
       "      <td>5070.0</td>\n",
       "      <td>64500</td>\n",
       "      <td>Wholesalers</td>\n",
       "      <td>Wholesalers: Health Care</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>CVS Health</td>\n",
       "      <td>184765.0</td>\n",
       "      <td>6622.0</td>\n",
       "      <td>203000</td>\n",
       "      <td>Health Care</td>\n",
       "      <td>Health Care: Pharmacy and Other Services</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Amazon.com</td>\n",
       "      <td>177866.0</td>\n",
       "      <td>3033.0</td>\n",
       "      <td>566000</td>\n",
       "      <td>Retailing</td>\n",
       "      <td>Internet Services and Retailing</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>AT&amp;T</td>\n",
       "      <td>160546.0</td>\n",
       "      <td>29450.0</td>\n",
       "      <td>254000</td>\n",
       "      <td>Telecommunications</td>\n",
       "      <td>Telecommunications</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>General Motors</td>\n",
       "      <td>157311.0</td>\n",
       "      <td>-3864.0</td>\n",
       "      <td>180000</td>\n",
       "      <td>Motor Vehicles &amp; Parts</td>\n",
       "      <td>Motor Vehicles and Parts</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>Ford Motor</td>\n",
       "      <td>156776.0</td>\n",
       "      <td>7602.0</td>\n",
       "      <td>202000</td>\n",
       "      <td>Motor Vehicles &amp; Parts</td>\n",
       "      <td>Motor Vehicles and Parts</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>AmerisourceBergen</td>\n",
       "      <td>153144.0</td>\n",
       "      <td>364.5</td>\n",
       "      <td>19500</td>\n",
       "      <td>Wholesalers</td>\n",
       "      <td>Wholesalers: Health Care</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>Chevron</td>\n",
       "      <td>134533.0</td>\n",
       "      <td>9195.0</td>\n",
       "      <td>51900</td>\n",
       "      <td>Energy</td>\n",
       "      <td>Petroleum Refining</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>Verizon</td>\n",
       "      <td>126034.0</td>\n",
       "      <td>30101.0</td>\n",
       "      <td>155400</td>\n",
       "      <td>Telecommunications</td>\n",
       "      <td>Telecommunications</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>Kroger</td>\n",
       "      <td>122662.0</td>\n",
       "      <td>1907.0</td>\n",
       "      <td>449000</td>\n",
       "      <td>Food &amp;  Drug Stores</td>\n",
       "      <td>Food and Drug Stores</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>General Electric</td>\n",
       "      <td>122274.0</td>\n",
       "      <td>-5786.0</td>\n",
       "      <td>313000</td>\n",
       "      <td>Industrials</td>\n",
       "      <td>Industrial Machinery</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>Walgreens Boots Alliance</td>\n",
       "      <td>118214.0</td>\n",
       "      <td>4078.0</td>\n",
       "      <td>290000</td>\n",
       "      <td>Food &amp;  Drug Stores</td>\n",
       "      <td>Food and Drug Stores</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>JPMorgan Chase</td>\n",
       "      <td>113899.0</td>\n",
       "      <td>24441.0</td>\n",
       "      <td>252539</td>\n",
       "      <td>Financials</td>\n",
       "      <td>Commercial Banks</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>Alphabet</td>\n",
       "      <td>110855.0</td>\n",
       "      <td>12662.0</td>\n",
       "      <td>80110</td>\n",
       "      <td>Technology</td>\n",
       "      <td>Internet Services and Retailing</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>Boeing</td>\n",
       "      <td>93392.0</td>\n",
       "      <td>8197.0</td>\n",
       "      <td>140800</td>\n",
       "      <td>Aerospace &amp; Defense</td>\n",
       "      <td>Aerospace and Defense</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>Procter &amp; Gamble</td>\n",
       "      <td>66217.0</td>\n",
       "      <td>15326.0</td>\n",
       "      <td>95000</td>\n",
       "      <td>Household Products</td>\n",
       "      <td>Household and Personal Products</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>UPS</td>\n",
       "      <td>65872.0</td>\n",
       "      <td>4910.0</td>\n",
       "      <td>346415</td>\n",
       "      <td>Transportation</td>\n",
       "      <td>Mail, Package, and Freight Delivery</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>PepsiCo</td>\n",
       "      <td>63525.0</td>\n",
       "      <td>4857.0</td>\n",
       "      <td>263000</td>\n",
       "      <td>Food, Beverages &amp; Tobacco</td>\n",
       "      <td>Food Consumer Products</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>DowDuPont</td>\n",
       "      <td>62683.0</td>\n",
       "      <td>1460.0</td>\n",
       "      <td>98000</td>\n",
       "      <td>Chemicals</td>\n",
       "      <td>Chemicals</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>Archer Daniels Midland</td>\n",
       "      <td>60828.0</td>\n",
       "      <td>1595.0</td>\n",
       "      <td>31300</td>\n",
       "      <td>Food, Beverages &amp; Tobacco</td>\n",
       "      <td>Food Production</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>FedEx</td>\n",
       "      <td>60319.0</td>\n",
       "      <td>2997.0</td>\n",
       "      <td>357000</td>\n",
       "      <td>Transportation</td>\n",
       "      <td>Mail, Package, and Freight Delivery</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>United Technologies</td>\n",
       "      <td>59837.0</td>\n",
       "      <td>4552.0</td>\n",
       "      <td>204700</td>\n",
       "      <td>Aerospace &amp; Defense</td>\n",
       "      <td>Aerospace and Defense</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>54</th>\n",
       "      <td>Disney</td>\n",
       "      <td>55137.0</td>\n",
       "      <td>8980.0</td>\n",
       "      <td>199000</td>\n",
       "      <td>Media</td>\n",
       "      <td>Entertainment</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>Caterpillar</td>\n",
       "      <td>45462.0</td>\n",
       "      <td>754.0</td>\n",
       "      <td>98400</td>\n",
       "      <td>Industrials</td>\n",
       "      <td>Construction and Farm Machinery</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>Nike</td>\n",
       "      <td>34350.0</td>\n",
       "      <td>4240.0</td>\n",
       "      <td>74400</td>\n",
       "      <td>Apparel</td>\n",
       "      <td>Apparel</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>Time Warner</td>\n",
       "      <td>31271.0</td>\n",
       "      <td>5247.0</td>\n",
       "      <td>26000</td>\n",
       "      <td>Media</td>\n",
       "      <td>Entertainment</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>123</th>\n",
       "      <td>International Paper</td>\n",
       "      <td>23302.0</td>\n",
       "      <td>2144.0</td>\n",
       "      <td>56000</td>\n",
       "      <td>Materials</td>\n",
       "      <td>Packaging, Containers</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>126</th>\n",
       "      <td>Marriott International</td>\n",
       "      <td>22894.0</td>\n",
       "      <td>1372.0</td>\n",
       "      <td>177000</td>\n",
       "      <td>Hotels, Restaurants &amp; Leisure</td>\n",
       "      <td>Hotels, Casinos, Resorts</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>130</th>\n",
       "      <td>McDonalds</td>\n",
       "      <td>22820.0</td>\n",
       "      <td>5192.3</td>\n",
       "      <td>235000</td>\n",
       "      <td>Hotels, Restaurants &amp; Leisure</td>\n",
       "      <td>Food Services</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>142</th>\n",
       "      <td>ManpowerGroup</td>\n",
       "      <td>21034.0</td>\n",
       "      <td>545.4</td>\n",
       "      <td>29000</td>\n",
       "      <td>Business Services</td>\n",
       "      <td>Temporary Help</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>150</th>\n",
       "      <td>Nucor</td>\n",
       "      <td>20252.0</td>\n",
       "      <td>1318.7</td>\n",
       "      <td>25100</td>\n",
       "      <td>Materials</td>\n",
       "      <td>Metals</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>152</th>\n",
       "      <td>Fluor</td>\n",
       "      <td>19521.0</td>\n",
       "      <td>191.4</td>\n",
       "      <td>56706</td>\n",
       "      <td>Engineering &amp; Construction</td>\n",
       "      <td>Engineering, Construction</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>160</th>\n",
       "      <td>Visa</td>\n",
       "      <td>18358.0</td>\n",
       "      <td>6699.0</td>\n",
       "      <td>15000</td>\n",
       "      <td>Business Services</td>\n",
       "      <td>Financial Data Services</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>162</th>\n",
       "      <td>Kimberly-Clark</td>\n",
       "      <td>18259.0</td>\n",
       "      <td>2278.0</td>\n",
       "      <td>42000</td>\n",
       "      <td>Household Products</td>\n",
       "      <td>Household and Personal Products</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>163</th>\n",
       "      <td>AECOM</td>\n",
       "      <td>18203.0</td>\n",
       "      <td>339.4</td>\n",
       "      <td>87000</td>\n",
       "      <td>Engineering &amp; Construction</td>\n",
       "      <td>Engineering, Construction</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>189</th>\n",
       "      <td>Sherwin-Williams</td>\n",
       "      <td>14984.0</td>\n",
       "      <td>1772.3</td>\n",
       "      <td>52695</td>\n",
       "      <td>Chemicals</td>\n",
       "      <td>Chemicals</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>241</th>\n",
       "      <td>VF</td>\n",
       "      <td>12400.0</td>\n",
       "      <td>614.9</td>\n",
       "      <td>69000</td>\n",
       "      <td>Apparel</td>\n",
       "      <td>Apparel</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      Company  Revenues  Profits  Employees  \\\n",
       "0                     Walmart  500343.0   9862.0    2300000   \n",
       "1                 Exxon Mobil  244363.0  19710.0      71200   \n",
       "2          Berkshire Hathaway  242137.0  44940.0     377000   \n",
       "3                       Apple  229234.0  48351.0     123000   \n",
       "4          UnitedHealth Group  201159.0  10558.0     260000   \n",
       "5                    McKesson  198533.0   5070.0      64500   \n",
       "6                  CVS Health  184765.0   6622.0     203000   \n",
       "7                  Amazon.com  177866.0   3033.0     566000   \n",
       "8                        AT&T  160546.0  29450.0     254000   \n",
       "9              General Motors  157311.0  -3864.0     180000   \n",
       "10                 Ford Motor  156776.0   7602.0     202000   \n",
       "11          AmerisourceBergen  153144.0    364.5      19500   \n",
       "12                    Chevron  134533.0   9195.0      51900   \n",
       "15                    Verizon  126034.0  30101.0     155400   \n",
       "16                     Kroger  122662.0   1907.0     449000   \n",
       "17           General Electric  122274.0  -5786.0     313000   \n",
       "18   Walgreens Boots Alliance  118214.0   4078.0     290000   \n",
       "19             JPMorgan Chase  113899.0  24441.0     252539   \n",
       "21                   Alphabet  110855.0  12662.0      80110   \n",
       "26                     Boeing   93392.0   8197.0     140800   \n",
       "41           Procter & Gamble   66217.0  15326.0      95000   \n",
       "43                        UPS   65872.0   4910.0     346415   \n",
       "44                    PepsiCo   63525.0   4857.0     263000   \n",
       "46                  DowDuPont   62683.0   1460.0      98000   \n",
       "47     Archer Daniels Midland   60828.0   1595.0      31300   \n",
       "49                      FedEx   60319.0   2997.0     357000   \n",
       "50        United Technologies   59837.0   4552.0     204700   \n",
       "54                     Disney   55137.0   8980.0     199000   \n",
       "64                Caterpillar   45462.0    754.0      98400   \n",
       "88                       Nike   34350.0   4240.0      74400   \n",
       "97                Time Warner   31271.0   5247.0      26000   \n",
       "123       International Paper   23302.0   2144.0      56000   \n",
       "126    Marriott International   22894.0   1372.0     177000   \n",
       "130                 McDonalds   22820.0   5192.3     235000   \n",
       "142             ManpowerGroup   21034.0    545.4      29000   \n",
       "150                     Nucor   20252.0   1318.7      25100   \n",
       "152                     Fluor   19521.0    191.4      56706   \n",
       "160                      Visa   18358.0   6699.0      15000   \n",
       "162            Kimberly-Clark   18259.0   2278.0      42000   \n",
       "163                     AECOM   18203.0    339.4      87000   \n",
       "189          Sherwin-Williams   14984.0   1772.3      52695   \n",
       "241                        VF   12400.0    614.9      69000   \n",
       "\n",
       "                            Sector                                  Industry  \n",
       "0                        Retailing                     General Merchandisers  \n",
       "1                           Energy                        Petroleum Refining  \n",
       "2                       Financials  Insurance: Property and Casualty (Stock)  \n",
       "3                       Technology               Computers, Office Equipment  \n",
       "4                      Health Care   Health Care: Insurance and Managed Care  \n",
       "5                      Wholesalers                  Wholesalers: Health Care  \n",
       "6                      Health Care  Health Care: Pharmacy and Other Services  \n",
       "7                        Retailing           Internet Services and Retailing  \n",
       "8               Telecommunications                        Telecommunications  \n",
       "9           Motor Vehicles & Parts                  Motor Vehicles and Parts  \n",
       "10          Motor Vehicles & Parts                  Motor Vehicles and Parts  \n",
       "11                     Wholesalers                  Wholesalers: Health Care  \n",
       "12                          Energy                        Petroleum Refining  \n",
       "15              Telecommunications                        Telecommunications  \n",
       "16             Food &  Drug Stores                      Food and Drug Stores  \n",
       "17                     Industrials                      Industrial Machinery  \n",
       "18             Food &  Drug Stores                      Food and Drug Stores  \n",
       "19                      Financials                          Commercial Banks  \n",
       "21                      Technology           Internet Services and Retailing  \n",
       "26             Aerospace & Defense                     Aerospace and Defense  \n",
       "41              Household Products           Household and Personal Products  \n",
       "43                  Transportation       Mail, Package, and Freight Delivery  \n",
       "44       Food, Beverages & Tobacco                    Food Consumer Products  \n",
       "46                       Chemicals                                 Chemicals  \n",
       "47       Food, Beverages & Tobacco                           Food Production  \n",
       "49                  Transportation       Mail, Package, and Freight Delivery  \n",
       "50             Aerospace & Defense                     Aerospace and Defense  \n",
       "54                           Media                             Entertainment  \n",
       "64                     Industrials           Construction and Farm Machinery  \n",
       "88                         Apparel                                   Apparel  \n",
       "97                           Media                             Entertainment  \n",
       "123                      Materials                     Packaging, Containers  \n",
       "126  Hotels, Restaurants & Leisure                  Hotels, Casinos, Resorts  \n",
       "130  Hotels, Restaurants & Leisure                             Food Services  \n",
       "142              Business Services                            Temporary Help  \n",
       "150                      Materials                                    Metals  \n",
       "152     Engineering & Construction                 Engineering, Construction  \n",
       "160              Business Services                   Financial Data Services  \n",
       "162             Household Products           Household and Personal Products  \n",
       "163     Engineering & Construction                 Engineering, Construction  \n",
       "189                      Chemicals                                 Chemicals  \n",
       "241                        Apparel                                   Apparel  "
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sectors.head(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Company</th>\n",
       "      <th>Revenues</th>\n",
       "      <th>Profits</th>\n",
       "      <th>Employees</th>\n",
       "      <th>Sector</th>\n",
       "      <th>Industry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>473</th>\n",
       "      <td>Windstream Holdings</td>\n",
       "      <td>5853.0</td>\n",
       "      <td>-2116.6</td>\n",
       "      <td>12979</td>\n",
       "      <td>Telecommunications</td>\n",
       "      <td>Telecommunications</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>520</th>\n",
       "      <td>Telephone &amp; Data Systems</td>\n",
       "      <td>5044.0</td>\n",
       "      <td>153.0</td>\n",
       "      <td>9900</td>\n",
       "      <td>Telecommunications</td>\n",
       "      <td>Telecommunications</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>667</th>\n",
       "      <td>Weis Markets</td>\n",
       "      <td>3467.0</td>\n",
       "      <td>98.4</td>\n",
       "      <td>23000</td>\n",
       "      <td>Food &amp;  Drug Stores</td>\n",
       "      <td>Food and Drug Stores</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>759</th>\n",
       "      <td>Hain Celestial Group</td>\n",
       "      <td>2853.0</td>\n",
       "      <td>67.4</td>\n",
       "      <td>7825</td>\n",
       "      <td>Food, Beverages &amp; Tobacco</td>\n",
       "      <td>Food Consumer Products</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>774</th>\n",
       "      <td>Fossil Group</td>\n",
       "      <td>2788.0</td>\n",
       "      <td>-478.2</td>\n",
       "      <td>12300</td>\n",
       "      <td>Apparel</td>\n",
       "      <td>Apparel</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>SiteOne Landscape Supply</td>\n",
       "      <td>1862.0</td>\n",
       "      <td>54.6</td>\n",
       "      <td>3664</td>\n",
       "      <td>Wholesalers</td>\n",
       "      <td>Wholesalers: Diversified</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>Charles River Laboratories Intl</td>\n",
       "      <td>1858.0</td>\n",
       "      <td>123.4</td>\n",
       "      <td>11800</td>\n",
       "      <td>Health Care</td>\n",
       "      <td>Health Care: Pharmacy and Other Services</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>CoreLogic</td>\n",
       "      <td>1851.0</td>\n",
       "      <td>152.2</td>\n",
       "      <td>5900</td>\n",
       "      <td>Business Services</td>\n",
       "      <td>Financial Data Services</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>Ensign Group</td>\n",
       "      <td>1849.0</td>\n",
       "      <td>40.5</td>\n",
       "      <td>21301</td>\n",
       "      <td>Health Care</td>\n",
       "      <td>Health Care: Medical Facilities</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>HCP</td>\n",
       "      <td>1848.0</td>\n",
       "      <td>414.2</td>\n",
       "      <td>190</td>\n",
       "      <td>Financials</td>\n",
       "      <td>Real estate</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>63 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                             Company  Revenues  Profits  Employees  \\\n",
       "473              Windstream Holdings    5853.0  -2116.6      12979   \n",
       "520         Telephone & Data Systems    5044.0    153.0       9900   \n",
       "667                     Weis Markets    3467.0     98.4      23000   \n",
       "759             Hain Celestial Group    2853.0     67.4       7825   \n",
       "774                     Fossil Group    2788.0   -478.2      12300   \n",
       "..                               ...       ...      ...        ...   \n",
       "995         SiteOne Landscape Supply    1862.0     54.6       3664   \n",
       "996  Charles River Laboratories Intl    1858.0    123.4      11800   \n",
       "997                        CoreLogic    1851.0    152.2       5900   \n",
       "998                     Ensign Group    1849.0     40.5      21301   \n",
       "999                              HCP    1848.0    414.2        190   \n",
       "\n",
       "                        Sector                                  Industry  \n",
       "473         Telecommunications                        Telecommunications  \n",
       "520         Telecommunications                        Telecommunications  \n",
       "667        Food &  Drug Stores                      Food and Drug Stores  \n",
       "759  Food, Beverages & Tobacco                    Food Consumer Products  \n",
       "774                    Apparel                                   Apparel  \n",
       "..                         ...                                       ...  \n",
       "995                Wholesalers                  Wholesalers: Diversified  \n",
       "996                Health Care  Health Care: Pharmacy and Other Services  \n",
       "997          Business Services                   Financial Data Services  \n",
       "998                Health Care           Health Care: Medical Facilities  \n",
       "999                 Financials                               Real estate  \n",
       "\n",
       "[63 rows x 6 columns]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sectors.tail(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Company</th>\n",
       "      <th>Revenues</th>\n",
       "      <th>Profits</th>\n",
       "      <th>Employees</th>\n",
       "      <th>Sector</th>\n",
       "      <th>Industry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Exxon Mobil</td>\n",
       "      <td>244363.0</td>\n",
       "      <td>19710.0</td>\n",
       "      <td>71200</td>\n",
       "      <td>Energy</td>\n",
       "      <td>Petroleum Refining</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>Chevron</td>\n",
       "      <td>134533.0</td>\n",
       "      <td>9195.0</td>\n",
       "      <td>51900</td>\n",
       "      <td>Energy</td>\n",
       "      <td>Petroleum Refining</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>Phillips 66</td>\n",
       "      <td>91568.0</td>\n",
       "      <td>5106.0</td>\n",
       "      <td>14600</td>\n",
       "      <td>Energy</td>\n",
       "      <td>Petroleum Refining</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>Valero Energy</td>\n",
       "      <td>88407.0</td>\n",
       "      <td>4065.0</td>\n",
       "      <td>10015</td>\n",
       "      <td>Energy</td>\n",
       "      <td>Petroleum Refining</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>Marathon Petroleum</td>\n",
       "      <td>67610.0</td>\n",
       "      <td>3432.0</td>\n",
       "      <td>43800</td>\n",
       "      <td>Energy</td>\n",
       "      <td>Petroleum Refining</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               Company  Revenues  Profits  Employees  Sector  \\\n",
       "1          Exxon Mobil  244363.0  19710.0      71200  Energy   \n",
       "12             Chevron  134533.0   9195.0      51900  Energy   \n",
       "27         Phillips 66   91568.0   5106.0      14600  Energy   \n",
       "30       Valero Energy   88407.0   4065.0      10015  Energy   \n",
       "40  Marathon Petroleum   67610.0   3432.0      43800  Energy   \n",
       "\n",
       "              Industry  \n",
       "1   Petroleum Refining  \n",
       "12  Petroleum Refining  \n",
       "27  Petroleum Refining  \n",
       "30  Petroleum Refining  \n",
       "40  Petroleum Refining  "
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sectors.get_group(\"Energy\").head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 9.4 Aggregate Operations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Revenues</th>\n",
       "      <th>Profits</th>\n",
       "      <th>Employees</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sector</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Aerospace &amp; Defense</th>\n",
       "      <td>383835.0</td>\n",
       "      <td>26733.5</td>\n",
       "      <td>1010124</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Apparel</th>\n",
       "      <td>101157.3</td>\n",
       "      <td>6350.7</td>\n",
       "      <td>355699</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Business Services</th>\n",
       "      <td>316090.0</td>\n",
       "      <td>37179.2</td>\n",
       "      <td>1593999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chemicals</th>\n",
       "      <td>251151.0</td>\n",
       "      <td>20475.0</td>\n",
       "      <td>474020</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Energy</th>\n",
       "      <td>1543507.2</td>\n",
       "      <td>85369.6</td>\n",
       "      <td>981207</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Engineering &amp; Construction</th>\n",
       "      <td>172782.0</td>\n",
       "      <td>7121.0</td>\n",
       "      <td>420745</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Financials</th>\n",
       "      <td>2442480.0</td>\n",
       "      <td>264253.5</td>\n",
       "      <td>3500119</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Food &amp;  Drug Stores</th>\n",
       "      <td>405468.0</td>\n",
       "      <td>8440.3</td>\n",
       "      <td>1398074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Food, Beverages &amp; Tobacco</th>\n",
       "      <td>510232.0</td>\n",
       "      <td>54902.5</td>\n",
       "      <td>1079316</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Health Care</th>\n",
       "      <td>1507991.4</td>\n",
       "      <td>92791.1</td>\n",
       "      <td>2971189</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                             Revenues   Profits  Employees\n",
       "Sector                                                    \n",
       "Aerospace & Defense          383835.0   26733.5    1010124\n",
       "Apparel                      101157.3    6350.7     355699\n",
       "Business Services            316090.0   37179.2    1593999\n",
       "Chemicals                    251151.0   20475.0     474020\n",
       "Energy                      1543507.2   85369.6     981207\n",
       "Engineering & Construction   172782.0    7121.0     420745\n",
       "Financials                  2442480.0  264253.5    3500119\n",
       "Food &  Drug Stores          405468.0    8440.3    1398074\n",
       "Food, Beverages & Tobacco    510232.0   54902.5    1079316\n",
       "Health Care                 1507991.4   92791.1    2971189"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sectors.sum().head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Company</th>\n",
       "      <th>Revenues</th>\n",
       "      <th>Profits</th>\n",
       "      <th>Employees</th>\n",
       "      <th>Sector</th>\n",
       "      <th>Industry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>Boeing</td>\n",
       "      <td>93392.0</td>\n",
       "      <td>8197.0</td>\n",
       "      <td>140800</td>\n",
       "      <td>Aerospace &amp; Defense</td>\n",
       "      <td>Aerospace and Defense</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>United Technologies</td>\n",
       "      <td>59837.0</td>\n",
       "      <td>4552.0</td>\n",
       "      <td>204700</td>\n",
       "      <td>Aerospace &amp; Defense</td>\n",
       "      <td>Aerospace and Defense</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58</th>\n",
       "      <td>Lockheed Martin</td>\n",
       "      <td>51048.0</td>\n",
       "      <td>2002.0</td>\n",
       "      <td>100000</td>\n",
       "      <td>Aerospace &amp; Defense</td>\n",
       "      <td>Aerospace and Defense</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>General Dynamics</td>\n",
       "      <td>30973.0</td>\n",
       "      <td>2912.0</td>\n",
       "      <td>98600</td>\n",
       "      <td>Aerospace &amp; Defense</td>\n",
       "      <td>Aerospace and Defense</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>117</th>\n",
       "      <td>Northrop Grumman</td>\n",
       "      <td>25803.0</td>\n",
       "      <td>2015.0</td>\n",
       "      <td>70000</td>\n",
       "      <td>Aerospace &amp; Defense</td>\n",
       "      <td>Aerospace and Defense</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 Company  Revenues  Profits  Employees               Sector  \\\n",
       "26                Boeing   93392.0   8197.0     140800  Aerospace & Defense   \n",
       "50   United Technologies   59837.0   4552.0     204700  Aerospace & Defense   \n",
       "58       Lockheed Martin   51048.0   2002.0     100000  Aerospace & Defense   \n",
       "98      General Dynamics   30973.0   2912.0      98600  Aerospace & Defense   \n",
       "117     Northrop Grumman   25803.0   2015.0      70000  Aerospace & Defense   \n",
       "\n",
       "                  Industry  \n",
       "26   Aerospace and Defense  \n",
       "50   Aerospace and Defense  \n",
       "58   Aerospace and Defense  \n",
       "98   Aerospace and Defense  \n",
       "117  Aerospace and Defense  "
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sectors.get_group(\"Aerospace & Defense\").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "26     93392.0\n",
       "50     59837.0\n",
       "58     51048.0\n",
       "98     30973.0\n",
       "117    25803.0\n",
       "Name: Revenues, dtype: float64"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sectors.get_group(\"Aerospace & Defense\").loc[:,\"Revenues\"].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "383835.0"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sectors.get_group(\"Aerospace & Defense\").loc[:, \"Revenues\"].sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Revenues</th>\n",
       "      <th>Profits</th>\n",
       "      <th>Employees</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sector</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Aerospace &amp; Defense</th>\n",
       "      <td>15353.400000</td>\n",
       "      <td>1069.340000</td>\n",
       "      <td>40404.960000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Apparel</th>\n",
       "      <td>7225.521429</td>\n",
       "      <td>453.621429</td>\n",
       "      <td>25407.071429</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Business Services</th>\n",
       "      <td>5963.962264</td>\n",
       "      <td>701.494340</td>\n",
       "      <td>30075.452830</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chemicals</th>\n",
       "      <td>7610.636364</td>\n",
       "      <td>620.454545</td>\n",
       "      <td>14364.242424</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Energy</th>\n",
       "      <td>14425.300935</td>\n",
       "      <td>805.373585</td>\n",
       "      <td>9170.158879</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         Revenues      Profits     Employees\n",
       "Sector                                                      \n",
       "Aerospace & Defense  15353.400000  1069.340000  40404.960000\n",
       "Apparel               7225.521429   453.621429  25407.071429\n",
       "Business Services     5963.962264   701.494340  30075.452830\n",
       "Chemicals             7610.636364   620.454545  14364.242424\n",
       "Energy               14425.300935   805.373585   9170.158879"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sectors.mean().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<pandas.core.groupby.generic.SeriesGroupBy object at 0x7fe669e6b070>"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sectors[\"Revenues\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Sector\n",
       "Aerospace & Defense     383835.0\n",
       "Apparel                 101157.3\n",
       "Business Services       316090.0\n",
       "Chemicals               251151.0\n",
       "Energy                 1543507.2\n",
       "Name: Revenues, dtype: float64"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sectors[\"Revenues\"].sum().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Sector\n",
       "Aerospace & Defense    40404.960000\n",
       "Apparel                25407.071429\n",
       "Business Services      30075.452830\n",
       "Chemicals              14364.242424\n",
       "Energy                  9170.158879\n",
       "Name: Employees, dtype: float64"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sectors[\"Employees\"].mean().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Sector\n",
       "Aerospace & Defense     8197.0\n",
       "Apparel                 4240.0\n",
       "Business Services       6699.0\n",
       "Chemicals               3000.4\n",
       "Energy                 19710.0\n",
       "Name: Profits, dtype: float64"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sectors[\"Profits\"].max().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Sector\n",
       "Aerospace & Defense    5157\n",
       "Apparel                3700\n",
       "Business Services      2338\n",
       "Chemicals              1931\n",
       "Energy                  593\n",
       "Name: Employees, dtype: int64"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sectors[\"Employees\"].min().head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 9.4.1 Applying Multiple Aggregations using the agg Method"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Revenues</th>\n",
       "      <th>Profits</th>\n",
       "      <th>Employees</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sector</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Aerospace &amp; Defense</th>\n",
       "      <td>1877.0</td>\n",
       "      <td>8197.0</td>\n",
       "      <td>40404.960000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Apparel</th>\n",
       "      <td>2350.0</td>\n",
       "      <td>4240.0</td>\n",
       "      <td>25407.071429</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Business Services</th>\n",
       "      <td>1851.0</td>\n",
       "      <td>6699.0</td>\n",
       "      <td>30075.452830</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chemicals</th>\n",
       "      <td>1925.0</td>\n",
       "      <td>3000.4</td>\n",
       "      <td>14364.242424</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Energy</th>\n",
       "      <td>1874.0</td>\n",
       "      <td>19710.0</td>\n",
       "      <td>9170.158879</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                     Revenues  Profits     Employees\n",
       "Sector                                              \n",
       "Aerospace & Defense    1877.0   8197.0  40404.960000\n",
       "Apparel                2350.0   4240.0  25407.071429\n",
       "Business Services      1851.0   6699.0  30075.452830\n",
       "Chemicals              1925.0   3000.4  14364.242424\n",
       "Energy                 1874.0  19710.0   9170.158879"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aggregations = {\n",
    "    \"Revenues\": \"min\",\n",
    "    \"Profits\": \"max\",\n",
    "    \"Employees\": \"mean\"\n",
    "}\n",
    "\n",
    "sectors.agg(aggregations).head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 9.5 Applying a Custom Operation to all Groups"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Company</th>\n",
       "      <th>Revenues</th>\n",
       "      <th>Profits</th>\n",
       "      <th>Employees</th>\n",
       "      <th>Sector</th>\n",
       "      <th>Industry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Apple</td>\n",
       "      <td>229234.0</td>\n",
       "      <td>48351.0</td>\n",
       "      <td>123000</td>\n",
       "      <td>Technology</td>\n",
       "      <td>Computers, Office Equipment</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Berkshire Hathaway</td>\n",
       "      <td>242137.0</td>\n",
       "      <td>44940.0</td>\n",
       "      <td>377000</td>\n",
       "      <td>Financials</td>\n",
       "      <td>Insurance: Property and Casualty (Stock)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>Verizon</td>\n",
       "      <td>126034.0</td>\n",
       "      <td>30101.0</td>\n",
       "      <td>155400</td>\n",
       "      <td>Telecommunications</td>\n",
       "      <td>Telecommunications</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>AT&amp;T</td>\n",
       "      <td>160546.0</td>\n",
       "      <td>29450.0</td>\n",
       "      <td>254000</td>\n",
       "      <td>Telecommunications</td>\n",
       "      <td>Telecommunications</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>JPMorgan Chase</td>\n",
       "      <td>113899.0</td>\n",
       "      <td>24441.0</td>\n",
       "      <td>252539</td>\n",
       "      <td>Financials</td>\n",
       "      <td>Commercial Banks</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               Company  Revenues  Profits  Employees              Sector  \\\n",
       "3                Apple  229234.0  48351.0     123000          Technology   \n",
       "2   Berkshire Hathaway  242137.0  44940.0     377000          Financials   \n",
       "15             Verizon  126034.0  30101.0     155400  Telecommunications   \n",
       "8                 AT&T  160546.0  29450.0     254000  Telecommunications   \n",
       "19      JPMorgan Chase  113899.0  24441.0     252539          Financials   \n",
       "\n",
       "                                    Industry  \n",
       "3                Computers, Office Equipment  \n",
       "2   Insurance: Property and Casualty (Stock)  \n",
       "15                        Telecommunications  \n",
       "8                         Telecommunications  \n",
       "19                          Commercial Banks  "
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fortune.nlargest(n = 5, columns = \"Profits\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_largest_row(df):\n",
    "    return df.nlargest(1, \"Revenues\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Company</th>\n",
       "      <th>Revenues</th>\n",
       "      <th>Profits</th>\n",
       "      <th>Employees</th>\n",
       "      <th>Sector</th>\n",
       "      <th>Industry</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sector</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Aerospace &amp; Defense</th>\n",
       "      <th>26</th>\n",
       "      <td>Boeing</td>\n",
       "      <td>93392.0</td>\n",
       "      <td>8197.0</td>\n",
       "      <td>140800</td>\n",
       "      <td>Aerospace &amp; Defense</td>\n",
       "      <td>Aerospace and Defense</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Apparel</th>\n",
       "      <th>88</th>\n",
       "      <td>Nike</td>\n",
       "      <td>34350.0</td>\n",
       "      <td>4240.0</td>\n",
       "      <td>74400</td>\n",
       "      <td>Apparel</td>\n",
       "      <td>Apparel</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Business Services</th>\n",
       "      <th>142</th>\n",
       "      <td>ManpowerGroup</td>\n",
       "      <td>21034.0</td>\n",
       "      <td>545.4</td>\n",
       "      <td>29000</td>\n",
       "      <td>Business Services</td>\n",
       "      <td>Temporary Help</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chemicals</th>\n",
       "      <th>46</th>\n",
       "      <td>DowDuPont</td>\n",
       "      <td>62683.0</td>\n",
       "      <td>1460.0</td>\n",
       "      <td>98000</td>\n",
       "      <td>Chemicals</td>\n",
       "      <td>Chemicals</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Energy</th>\n",
       "      <th>1</th>\n",
       "      <td>Exxon Mobil</td>\n",
       "      <td>244363.0</td>\n",
       "      <td>19710.0</td>\n",
       "      <td>71200</td>\n",
       "      <td>Energy</td>\n",
       "      <td>Petroleum Refining</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               Company  Revenues  Profits  Employees  \\\n",
       "Sector                                                                 \n",
       "Aerospace & Defense 26          Boeing   93392.0   8197.0     140800   \n",
       "Apparel             88            Nike   34350.0   4240.0      74400   \n",
       "Business Services   142  ManpowerGroup   21034.0    545.4      29000   \n",
       "Chemicals           46       DowDuPont   62683.0   1460.0      98000   \n",
       "Energy              1      Exxon Mobil  244363.0  19710.0      71200   \n",
       "\n",
       "                                      Sector               Industry  \n",
       "Sector                                                               \n",
       "Aerospace & Defense 26   Aerospace & Defense  Aerospace and Defense  \n",
       "Apparel             88               Apparel                Apparel  \n",
       "Business Services   142    Business Services         Temporary Help  \n",
       "Chemicals           46             Chemicals              Chemicals  \n",
       "Energy              1                 Energy     Petroleum Refining  "
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sectors.apply(get_largest_row).head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 9.6 Grouping by Multiple Columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "sector_and_industry = fortune.groupby(by = [\"Sector\", \"Industry\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Sector               Industry                                     \n",
       "Aerospace & Defense  Aerospace and Defense                            25\n",
       "Apparel              Apparel                                          14\n",
       "Business Services    Advertising, marketing                            2\n",
       "                     Diversified Outsourcing Services                 14\n",
       "                     Education                                         2\n",
       "                                                                      ..\n",
       "Transportation       Trucking, Truck Leasing                          11\n",
       "Wholesalers          Wholesalers: Diversified                         24\n",
       "                     Wholesalers: Electronics and Office Equipment     8\n",
       "                     Wholesalers: Food and Grocery                     6\n",
       "                     Wholesalers: Health Care                          6\n",
       "Length: 82, dtype: int64"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sector_and_industry.size()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Company</th>\n",
       "      <th>Revenues</th>\n",
       "      <th>Profits</th>\n",
       "      <th>Employees</th>\n",
       "      <th>Sector</th>\n",
       "      <th>Industry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>567</th>\n",
       "      <td>Laureate Education</td>\n",
       "      <td>4378.0</td>\n",
       "      <td>91.5</td>\n",
       "      <td>54500</td>\n",
       "      <td>Business Services</td>\n",
       "      <td>Education</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>810</th>\n",
       "      <td>Graham Holdings</td>\n",
       "      <td>2592.0</td>\n",
       "      <td>302.0</td>\n",
       "      <td>16153</td>\n",
       "      <td>Business Services</td>\n",
       "      <td>Education</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                Company  Revenues  Profits  Employees             Sector  \\\n",
       "567  Laureate Education    4378.0     91.5      54500  Business Services   \n",
       "810     Graham Holdings    2592.0    302.0      16153  Business Services   \n",
       "\n",
       "      Industry  \n",
       "567  Education  \n",
       "810  Education  "
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sector_and_industry.get_group((\"Business Services\", \"Education\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Revenues</th>\n",
       "      <th>Profits</th>\n",
       "      <th>Employees</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sector</th>\n",
       "      <th>Industry</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Aerospace &amp; Defense</th>\n",
       "      <th>Aerospace and Defense</th>\n",
       "      <td>383835.0</td>\n",
       "      <td>26733.5</td>\n",
       "      <td>1010124</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Apparel</th>\n",
       "      <th>Apparel</th>\n",
       "      <td>101157.3</td>\n",
       "      <td>6350.7</td>\n",
       "      <td>355699</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">Business Services</th>\n",
       "      <th>Advertising, marketing</th>\n",
       "      <td>23156.0</td>\n",
       "      <td>1667.4</td>\n",
       "      <td>127500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Diversified Outsourcing Services</th>\n",
       "      <td>74175.0</td>\n",
       "      <td>5043.7</td>\n",
       "      <td>858600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Education</th>\n",
       "      <td>6970.0</td>\n",
       "      <td>393.5</td>\n",
       "      <td>70653</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                      Revenues  Profits  \\\n",
       "Sector              Industry                                              \n",
       "Aerospace & Defense Aerospace and Defense             383835.0  26733.5   \n",
       "Apparel             Apparel                           101157.3   6350.7   \n",
       "Business Services   Advertising, marketing             23156.0   1667.4   \n",
       "                    Diversified Outsourcing Services   74175.0   5043.7   \n",
       "                    Education                           6970.0    393.5   \n",
       "\n",
       "                                                      Employees  \n",
       "Sector              Industry                                     \n",
       "Aerospace & Defense Aerospace and Defense               1010124  \n",
       "Apparel             Apparel                              355699  \n",
       "Business Services   Advertising, marketing               127500  \n",
       "                    Diversified Outsourcing Services     858600  \n",
       "                    Education                             70653  "
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sector_and_industry.sum().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Sector               Industry                        \n",
       "Aerospace & Defense  Aerospace and Defense               15353.400000\n",
       "Apparel              Apparel                              7225.521429\n",
       "Business Services    Advertising, marketing              11578.000000\n",
       "                     Diversified Outsourcing Services     5298.214286\n",
       "                     Education                            3485.000000\n",
       "Name: Revenues, dtype: float64"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sector_and_industry[\"Revenues\"].mean().head(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 9.7 Coding Challenge"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Manufacturer</th>\n",
       "      <th>Type</th>\n",
       "      <th>Calories</th>\n",
       "      <th>Fiber</th>\n",
       "      <th>Sugars</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100% Bran</td>\n",
       "      <td>Nabisco</td>\n",
       "      <td>Cold</td>\n",
       "      <td>70</td>\n",
       "      <td>10.0</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>100% Natural Bran</td>\n",
       "      <td>Quaker Oats</td>\n",
       "      <td>Cold</td>\n",
       "      <td>120</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>All-Bran</td>\n",
       "      <td>Kellogg's</td>\n",
       "      <td>Cold</td>\n",
       "      <td>70</td>\n",
       "      <td>9.0</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>All-Bran with Extra Fiber</td>\n",
       "      <td>Kellogg's</td>\n",
       "      <td>Cold</td>\n",
       "      <td>50</td>\n",
       "      <td>14.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Almond Delight</td>\n",
       "      <td>Ralston Purina</td>\n",
       "      <td>Cold</td>\n",
       "      <td>110</td>\n",
       "      <td>1.0</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        Name    Manufacturer  Type  Calories  Fiber  Sugars\n",
       "0                  100% Bran         Nabisco  Cold        70   10.0       6\n",
       "1          100% Natural Bran     Quaker Oats  Cold       120    2.0       8\n",
       "2                   All-Bran       Kellogg's  Cold        70    9.0       5\n",
       "3  All-Bran with Extra Fiber       Kellogg's  Cold        50   14.0       0\n",
       "4             Almond Delight  Ralston Purina  Cold       110    1.0       8"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cereals = pd.read_csv(\"cereals.csv\")\n",
    "cereals.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 9.7.1 Problems"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 9.7.2 Solutions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "manufacturers = cereals.groupby(\"Manufacturer\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(manufacturers)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Manufacturer\n",
       "American Home Food Products     1\n",
       "General Mills                  22\n",
       "Kellogg's                      23\n",
       "Nabisco                         6\n",
       "Post                            9\n",
       "Quaker Oats                     8\n",
       "Ralston Purina                  8\n",
       "dtype: int64"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "manufacturers.size()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Manufacturer</th>\n",
       "      <th>Type</th>\n",
       "      <th>Calories</th>\n",
       "      <th>Fiber</th>\n",
       "      <th>Sugars</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100% Bran</td>\n",
       "      <td>Nabisco</td>\n",
       "      <td>Cold</td>\n",
       "      <td>70</td>\n",
       "      <td>10.0</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>Cream of Wheat (Quick)</td>\n",
       "      <td>Nabisco</td>\n",
       "      <td>Hot</td>\n",
       "      <td>100</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>Shredded Wheat</td>\n",
       "      <td>Nabisco</td>\n",
       "      <td>Cold</td>\n",
       "      <td>80</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>Shredded Wheat 'n'Bran</td>\n",
       "      <td>Nabisco</td>\n",
       "      <td>Cold</td>\n",
       "      <td>90</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>Shredded Wheat spoon size</td>\n",
       "      <td>Nabisco</td>\n",
       "      <td>Cold</td>\n",
       "      <td>90</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>68</th>\n",
       "      <td>Strawberry Fruit Wheats</td>\n",
       "      <td>Nabisco</td>\n",
       "      <td>Cold</td>\n",
       "      <td>90</td>\n",
       "      <td>3.0</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         Name Manufacturer  Type  Calories  Fiber  Sugars\n",
       "0                   100% Bran      Nabisco  Cold        70   10.0       6\n",
       "20     Cream of Wheat (Quick)      Nabisco   Hot       100    1.0       0\n",
       "63             Shredded Wheat      Nabisco  Cold        80    3.0       0\n",
       "64     Shredded Wheat 'n'Bran      Nabisco  Cold        90    4.0       0\n",
       "65  Shredded Wheat spoon size      Nabisco  Cold        90    3.0       0\n",
       "68    Strawberry Fruit Wheats      Nabisco  Cold        90    3.0       5"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "manufacturers.get_group(\"Nabisco\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Calories</th>\n",
       "      <th>Fiber</th>\n",
       "      <th>Sugars</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Manufacturer</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>American Home Food Products</th>\n",
       "      <td>100.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>3.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>General Mills</th>\n",
       "      <td>111.363636</td>\n",
       "      <td>1.272727</td>\n",
       "      <td>7.954545</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kellogg's</th>\n",
       "      <td>108.695652</td>\n",
       "      <td>2.739130</td>\n",
       "      <td>7.565217</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Nabisco</th>\n",
       "      <td>86.666667</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>1.833333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Post</th>\n",
       "      <td>108.888889</td>\n",
       "      <td>2.777778</td>\n",
       "      <td>8.777778</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Quaker Oats</th>\n",
       "      <td>95.000000</td>\n",
       "      <td>1.337500</td>\n",
       "      <td>5.250000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ralston Purina</th>\n",
       "      <td>115.000000</td>\n",
       "      <td>1.875000</td>\n",
       "      <td>6.125000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               Calories     Fiber    Sugars\n",
       "Manufacturer                                               \n",
       "American Home Food Products  100.000000  0.000000  3.000000\n",
       "General Mills                111.363636  1.272727  7.954545\n",
       "Kellogg's                    108.695652  2.739130  7.565217\n",
       "Nabisco                       86.666667  4.000000  1.833333\n",
       "Post                         108.888889  2.777778  8.777778\n",
       "Quaker Oats                   95.000000  1.337500  5.250000\n",
       "Ralston Purina               115.000000  1.875000  6.125000"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "manufacturers.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Manufacturer\n",
       "American Home Food Products     3\n",
       "General Mills                  14\n",
       "Kellogg's                      15\n",
       "Nabisco                         6\n",
       "Post                           15\n",
       "Quaker Oats                    12\n",
       "Ralston Purina                 11\n",
       "Name: Sugars, dtype: int64"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "manufacturers[\"Sugars\"].max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Manufacturer\n",
       "American Home Food Products    0.0\n",
       "General Mills                  0.0\n",
       "Kellogg's                      0.0\n",
       "Nabisco                        1.0\n",
       "Post                           0.0\n",
       "Quaker Oats                    0.0\n",
       "Ralston Purina                 0.0\n",
       "Name: Fiber, dtype: float64"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "manufacturers[\"Fiber\"].min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": [
    "def smallest_sugar_row(df):\n",
    "    return df.nsmallest(1, \"Sugars\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Manufacturer</th>\n",
       "      <th>Type</th>\n",
       "      <th>Calories</th>\n",
       "      <th>Fiber</th>\n",
       "      <th>Sugars</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Manufacturer</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>American Home Food Products</th>\n",
       "      <th>43</th>\n",
       "      <td>Maypo</td>\n",
       "      <td>American Home Food Products</td>\n",
       "      <td>Hot</td>\n",
       "      <td>100</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>General Mills</th>\n",
       "      <th>11</th>\n",
       "      <td>Cheerios</td>\n",
       "      <td>General Mills</td>\n",
       "      <td>Cold</td>\n",
       "      <td>110</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kellogg's</th>\n",
       "      <th>3</th>\n",
       "      <td>All-Bran with Extra Fiber</td>\n",
       "      <td>Kellogg's</td>\n",
       "      <td>Cold</td>\n",
       "      <td>50</td>\n",
       "      <td>14.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Nabisco</th>\n",
       "      <th>20</th>\n",
       "      <td>Cream of Wheat (Quick)</td>\n",
       "      <td>Nabisco</td>\n",
       "      <td>Hot</td>\n",
       "      <td>100</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Post</th>\n",
       "      <th>33</th>\n",
       "      <td>Grape-Nuts</td>\n",
       "      <td>Post</td>\n",
       "      <td>Cold</td>\n",
       "      <td>110</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Quaker Oats</th>\n",
       "      <th>57</th>\n",
       "      <td>Quaker Oatmeal</td>\n",
       "      <td>Quaker Oats</td>\n",
       "      <td>Hot</td>\n",
       "      <td>100</td>\n",
       "      <td>2.7</td>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ralston Purina</th>\n",
       "      <th>61</th>\n",
       "      <td>Rice Chex</td>\n",
       "      <td>Ralston Purina</td>\n",
       "      <td>Cold</td>\n",
       "      <td>110</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                     Name  \\\n",
       "Manufacturer                                                \n",
       "American Home Food Products 43                      Maypo   \n",
       "General Mills               11                   Cheerios   \n",
       "Kellogg's                   3   All-Bran with Extra Fiber   \n",
       "Nabisco                     20     Cream of Wheat (Quick)   \n",
       "Post                        33                 Grape-Nuts   \n",
       "Quaker Oats                 57             Quaker Oatmeal   \n",
       "Ralston Purina              61                  Rice Chex   \n",
       "\n",
       "                                               Manufacturer  Type  Calories  \\\n",
       "Manufacturer                                                                  \n",
       "American Home Food Products 43  American Home Food Products   Hot       100   \n",
       "General Mills               11                General Mills  Cold       110   \n",
       "Kellogg's                   3                     Kellogg's  Cold        50   \n",
       "Nabisco                     20                      Nabisco   Hot       100   \n",
       "Post                        33                         Post  Cold       110   \n",
       "Quaker Oats                 57                  Quaker Oats   Hot       100   \n",
       "Ralston Purina              61               Ralston Purina  Cold       110   \n",
       "\n",
       "                                Fiber  Sugars  \n",
       "Manufacturer                                   \n",
       "American Home Food Products 43    0.0       3  \n",
       "General Mills               11    2.0       1  \n",
       "Kellogg's                   3    14.0       0  \n",
       "Nabisco                     20    1.0       0  \n",
       "Post                        33    3.0       3  \n",
       "Quaker Oats                 57    2.7      -1  \n",
       "Ralston Purina              61    0.0       2  "
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "manufacturers.apply(smallest_sugar_row)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 9.8 Summary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
